NestJS Junior interview questions and answers
75 questions for a NestJS (Junior) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.What is NestJS?
- 2.Which HTTP platform does NestJS use by default?
- 3.How do you create a new NestJS project?
- 4.What does
main.tsusually contain in a Nest app? - 5.What language does NestJS primarily use?
- 6.Which three building blocks make up most of a Nest feature?
- 7.What does the
nest g resource userscommand do? - 8.Why does Nest use decorators like
@Controller()and@Injectable()? - 9.What does the
@Module()decorator describe? - 10.
OrdersModuleneedsUsersServicefromUsersModule. What must be true? - 11.What does
@Global()on a module do? - 12.Are module providers singletons by default?
- 13.Why split an application into feature modules?
- 14.What is a typical way to load environment configuration in Nest?
- 15.What is the role of a controller?
- 16.Which route does this handler serve?
- 17.How do you read the JSON body of a POST request in a controller?
- 18.What status code does a
@Post()handler return by default? - 19.What happens if a controller method returns a plain object?
- 20.What is a DTO in Nest?
- 21.Why should a DTO be a class rather than a TypeScript interface?
- 22.How do you read
?page=2in a controller? - 23.What is a provider in Nest?
- 24.How does a controller get a service instance?
- 25.What is the main benefit of dependency injection?
- 26.What does
@Injectable()mark? - 27.What does the error 'Nest can't resolve dependencies of the UsersController (?)' usually mean?
- 28.How do you register a plain value as a provider, e.g. a config object?
- 29.What does a pipe do in Nest?
- 30.What does
@Param('id', ParseIntPipe) id: numberdo with/users/abc? - 31.How is request body validation usually set up?
- 32.What does the
whitelist: trueoption ofValidationPipedo? - 33.What does
transform: trueinValidationPipegive you? - 34.How do you return a 404 from a service or controller?
- 35.What does Nest return if a handler throws a plain
Error? - 36.Which built-in exceptions map to 400, 401 and 403?
- 37.What is an exception filter?
- 38.What is middleware in Nest?
- 39.What is the job of a guard?
- 40.How do you protect a route with a guard?
- 41.What can an interceptor do?
- 42.Where do you configure CORS in a Nest app?
- 43.Where should business logic live in a Nest app?
- 44.Which ORMs and database tools are commonly used with Nest?
- 45.How is TypeORM typically connected to a Nest app?
- 46.How do you use Prisma in Nest?
- 47.Why are async methods common in Nest services?
- 48.How do you create a testing module in Nest?
- 49.How do you replace a real service with a mock in a Nest test?
- 50.What does an e2e test in a Nest project typically do?
- 51.Which test runner does the default Nest project use?
- 52.How is JWT authentication often implemented in Nest?
- 53.How can you mark some routes as public when an auth guard is global?
- 54.How do you add rate limiting to a Nest API?
- 55.Why should password hashes never be returned in API responses?
- 56.How do you generate OpenAPI (Swagger) docs in Nest?
- 57.What does
app.setGlobalPrefix('api')do? - 58.Which built-in logger does Nest provide?
- 59.How do you run a method on a schedule, e.g. every night?
- 60.What is
@nestjs/terminusused for? - 61.How do you handle file uploads in a Nest app on Express?
- 62.What does
ClassSerializerInterceptordo together withclass-transformer? - 63.Which lifecycle hook runs once a module's dependencies are resolved?
- 64.What must you call so that shutdown hooks run on
SIGTERM? - 65.How is a typical Nest project organized?
- 66.What does
@Res()in a handler change? - 67.Can Nest serve GraphQL instead of REST?
- 68.What does
nest start --watchdo? - 69.How do you send a custom header from a handler without using
@Res()? - 70.What is the default TypeScript setting Nest projects need for DI by type?
- 71.What does
PartialType(CreateUserDto)give you? - 72.What does
@Query('limit', new DefaultValuePipe(20), ParseIntPipe) limit: numberdo whenlimitis missing? - 73.How do you call an external HTTP API from a Nest service in the Nest way?
- 74.Why use
TypeOrmModule.forRootAsync({ useFactory, inject: [ConfigService] })instead offorRoot({...})? - 75.Why prefer
@Body(),@Param()and@Query()over@Req()in handlers?