In a NestJS application running in production, why is proper error handling important?
Think about what happens if an unexpected error occurs in a live app.
Proper error handling ensures the app does not crash unexpectedly and helps developers track issues through logs.
Consider a NestJS app running in production with logging disabled. What is the likely outcome?
Think about how logs help developers after deployment.
Logging is essential in production to monitor app health and diagnose issues quickly.
Which NestJS lifecycle hook is best suited to perform cleanup tasks before the app shuts down in production?
Consider which hook runs just before the app stops.
The beforeApplicationShutdown hook allows cleanup like closing database connections before shutdown.
Given this NestJS service code snippet running in production mode, what will be logged?
import { Injectable, Logger } from '@nestjs/common'; @Injectable() export class AppService { private readonly logger = new Logger(AppService.name); getHello(): string { this.logger.debug('Debug message'); this.logger.log('Log message'); return 'Hello World!'; } } // Assume NestJS default logger settings in production mode
Think about NestJS default log levels in production.
By default, NestJS logger outputs 'log', 'warn', and 'error' levels in production mode. 'debug' messages are ignored unless explicitly enabled.
Consider this NestJS controller method. What happens when calling GET /users/abc?
import { Controller, Get, Param } from '@nestjs/common'; @Controller('users') export class UserController { @Get(':id') getUser(@Param('id') id: number) { return `User ID is ${id}`; } }
Consider how NestJS handles parameter types in @Param decorator.
The @Param decorator always returns string values. The method expects a number but does not convert it, so 'id' is a string. No runtime error occurs; the string is used as is.