Categories
JavaScript Answers

How to make synchronous requests in Node.js?

Spread the love

To make synchronous requests in Node.js, we use the sync-request module.

For instance, we write

const request = require("sync-request");

//...

try {
  const res = request("GET", url);
} catch (e) {
  console.log(e);
}

to call request to make a get request to url.

We use the catch block to catch any request errors.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.