Categories
JavaScript Answers

How to make HTTP requests with gzip/deflate compression with Node?

Spread the love

To make HTTP requests with gzip/deflate compression with Node, we set the gzip property.

For instance, we write

request(
  { method: "GET", uri: "http://www.example.com", gzip: true },
  (error, response, body) => {
    console.log(response.headers["content-encoding"]);
    console.log(body);
  }
);

to call request with an object with the gzip option set to true to make request with gzip compression.

Then we get the response headers from response.headers and the response body from body.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.