How to make requests in sequential order Node.js?

Sometimes, we want to make requests in sequential order Node.js.

In this article, we’ll look at how to make requests in sequential order Node.js.

How to make requests in sequential order Node.js?

To make requests in sequential order Node.js, we can use axios.

To install it, we run

npm i axios

Then we write

const axios = require('axios')

const makeRequests = async () => {
  const {
    data
  } = await axios.get(url1)
  const {
    data: data2
  } = await axios.get(url2)
  const {
    data: data3
  } = await axios.get(url3)
}

to call axios.get to make GET requests to 3 different URLs url1, url2, and url3.

And we get the response from the data property of the resolved value of each promise.

await returns the resolve value of the promise.

Conclusion

To make requests in sequential order Node.js, we can use axios.