Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a NestJS route send in response a pretty formatted JSON

Tags:

json

nestjs

I have a NestJS route which sends back in response, a JSON not well formatted (like minified), I want to make this JSON easier to read, like a JSON prettier or JSON formatted, Do someone knows how to do it in NestJS ? I accept answers for other NodeJS frameworks like Express, maybe it will work in NestJS too...

like image 288
VersifiXion Avatar asked Nov 22 '25 14:11

VersifiXion


1 Answers

It works for me:

// src/main.ts
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  if (process.env.NODE_ENV !== 'production') {
    app.getHttpAdapter().getInstance().set('json spaces', 2);
  }
  await app.listen(process.env.PORT);
}
like image 127
Misael Abanto Avatar answered Nov 25 '25 08:11

Misael Abanto