Performance: Why production readiness matters
This concept impacts the overall stability, speed, and reliability of a NestJS application when deployed to real users.
import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import helmet from 'helmet'; import compression from 'compression'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.use(helmet()); // security headers app.use(compression()); // reduce response size app.enableShutdownHooks(); // graceful shutdown await app.listen(3000); } bootstrap();
import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); await app.listen(3000); } bootstrap();
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No production readiness setup | N/A (server-side) | N/A | N/A | [X] Bad |
| With compression and security middleware | N/A (server-side) | N/A | N/A | [OK] Good |
app.useGlobalFilters(new AllExceptionsFilter());
// Inside AllExceptionsFilter class
catch(exception, host) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const status = exception.getStatus ? exception.getStatus() : 500;
response.status(status).json({
statusCode: status,
message: 'Internal server error',
});
}
What will the client receive if an unexpected error occurs?import { Logger } from '@nestjs/common';
const logger = new Logger('AppModule');
function startApp() {
logger.log('Starting app...');
// Missing logger.error usage here
}
startApp();
What is the main issue regarding production readiness?Pass the test and this pattern moves unknown