Categories
JavaScript Answers

How to make synchronous requests in Node.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *