Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a REST API With Express Building API Routes in Express Using Middleware in Express

Thomas Dimnet
.a{fill-rule:evenodd;}techdegree seal-36
Thomas Dimnet
Python Development Techdegree Graduate 43,629 Points

Manage multiple asynchronous calls with Express

Hi there,

I understand the id of the next middleware and when to use it. But I am wondering how to work with multiple asynchronous calls with express (either when building an express rest api or when rendering templates directly with express and pug).

Do we use promises and new ES7 methods like async/await or is there some other solutions?



1 Answer

2,771 Points

Hi Thomas

I believe you can use both promises and callback functions to do async calls.

But using promises is a lot cleaner and can prevent calling functions more than once, since the promise will return and will not execute the rest.

I suggest you have a look at axios, it is fantastic package.


I hope this helps.

Good luck