Making Asynchronous HTTP Requests with in Node.js

Feb 3, 2024 ยท 2 min read

The method in Node.js provides a convenient way to make HTTP POST requests. However, by default it is a synchronous method that will block the event loop while the request is in progress. Here are some techniques for making asynchronous and non-blocking:

Use a Callback

The easiest way is to provide a callback function as the last argument to This callback will be invoked once the request finishes:, data, callback);

function callback(error, response, body) {
  if (!error && response.statusCode === 200) {
    // Request succeeded

This allows other code to run while the request is in progress, avoiding blocking the event loop.

Return a Promise

Another option is to wrap the call in a Promise:

function makeRequest() {
  return new Promise((resolve, reject) => {, data, (error, response, body) => {
      if (error) return reject(error);


This provides a clean interface using async/await.

Use Async Library

The async library has useful abstractions like async.parallel() to run multiple asynchronous operations concurrently:

  function(callback) {, callback);
  function(callback) {, callback);
], function(err, results) {
  // all requests completed

This allows coordinating multiple requests avoiding nested callbacks.

In summary, Node.js enables asynchronous I/O out of the box if you structure your code properly. Using callbacks, promises or helper libraries like async unlocks this powerful capability for non-blocking HTTP requests.

Browse by tags:

Browse by language:

The easiest way to do Web Scraping

Get HTML from any page with a simple API call. We handle proxy rotation, browser identities, automatic retries, CAPTCHAs, JavaScript rendering, etc automatically for you

Try ProxiesAPI for free

curl ""

<!doctype html>
    <title>Example Domain</title>
    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />


Don't leave just yet!

Enter your email below to claim your free API key: