Categories
JavaScript Answers

How to add Gzip compression with Node.js?

Spread the love

To add Gzip compression with Node.js, we use the compression package.

To install it, we run

npm install compression

Then we use it by writing

const express = require("express");
const compression = require("compression");

const app = express();
app.use(compression());

to call app.use with the middleware returned by the compression function to add gzip compression to our Express app.

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 *