Promises and async-await in Node.js

Learn the importance of promises and how to handle them using async-await.

What is a promise?

We often make a web request, an API request, or maybe a database request while creating software applications. These operations usually take a millisecond or probably more to get a connection and get the data back. So if we’re going to call it, store the response in a local variable, and try to access the response, we’ll always get into trouble (since the data may not be available instantly).

Then promises come into the picture. These operations usually return a promise, i.e., they say that they “promise” to bring something from the web, database, or any other source, in just a few milliseconds or even seconds, or else say that it failed.

Get hands-on with 1200+ tech skills courses.