Sometimes, we want to make synchronous requests in Node.js.
In this article, we’ll look at how to make synchronous requests in Node.js.
How to make synchronous requests in Node.js?
To make synchronous requests in Node.js, we can use the sync-request
module.
To install it, we run
npm i sync-request
Then we use it by writing
const request = require('sync-request')
try {
const res1 = request('GET', url1);
const res2 = request('GET', url2);
} catch (e) {}
to call request
with 'GET'
to make GET requests to url1
and url2
.
Conclusion
To make synchronous requests in Node.js, we can use the sync-request
module.