Compression (gzip) does not work in NestJS

Viewed 1126

Created a standard NestJS project using the command: nest new project-name. After that, I installed compression npm i --save compression and plugged it into the project.

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as compression from 'compression';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.use(compression());
  await app.listen(3000);
}
bootstrap();

But the compression does not work, response does not have gzip.

Response in browser

I've already tried clearing the cache, restarting the browser, nothing works.

Thanks for the help

1 Answers

If nothing else works:

  const expressApp = express();
  expressApp.use(compression());
  const expressAdapter = new ExpressAdapter(expressApp);
  const app = await NestFactory.create(AppModule, expressAdapter);
  await app.listen(3000);
Related