Search code examples
node.jsgzipnode.js-connect

How to enable gzip on my node server using connect?


I am trying to have my node server gzip the responses that it gives. I have the following:


const connect = require('connect');
const formDataRequests = ['communities/upsert'];
const app = connect();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
...

I did some research (example https://alligator.io/nodejs/compression/ ) but that requires and express app. Does anyone know what module I can import/etc to get this to gzip the responses?


Solution

  • According to the connect docs, you can use the same compression middleware:

    const compression = require('compression');
    app.use(compression());