NestJS Communication & Stakeholder Relations 4 — Questions and Answers
Question 1: Which NestJS built-in class is used to emit custom events within the same application process?
- EventGateway
- EventEmitter2 via @nestjs/event-emitter (Correct answer)
- Subject from RxJS
- BullQueue
Correct answer: EventEmitter2 via @nestjs/event-emitter
@nestjs/event-emitter wraps EventEmitter2 and integrates it with NestJS DI for in-process event communication.
Question 2: When documenting a paginated response for stakeholders, which @nestjs/swagger decorator best describes an array of items?
- @ApiResponse({ type: [ItemDto] })
- @ApiOkResponse({ type: ItemDto, isArray: true })
- Both A and B are correct (Correct answer)
- @ApiBearerAuth()
Correct answer: Both A and B are correct
Both @ApiResponse({ type: [ItemDto] }) and @ApiOkResponse({ type: ItemDto, isArray: true }) correctly declare an array response in Swagger.
Question 3: A QA team reports that WebSocket messages arrive out of order under load. Which NestJS pattern helps serialize message handling per client?
- Using async/await in gateway handlers (Correct answer)
- Switching to REST
- Disabling Socket.IO
- Using @UseFilters on the gateway
Correct answer: Using async/await in gateway handlers
Marking gateway handler methods as async and using await ensures sequential processing of each client's messages.
Question 4: How does NestJS support gRPC as a transport layer for inter-service communication?
- Via the @nestjs/grpc package and .proto file definitions (Correct answer)
- Via built-in decorators without extra packages
- Via REST-to-gRPC auto-conversion
- Via GraphQL subscriptions
Correct answer: Via the @nestjs/grpc package and .proto file definitions
@nestjs/microservices includes gRPC support using .proto files to define service contracts between teams.
Question 5: A security-conscious stakeholder wants API keys validated before any route is accessed. Which NestJS construct is the right tool?
- Pipe
- Guard (Correct answer)
- Interceptor
- Middleware
Correct answer: Guard
Guards implement the CanActivate interface and are specifically designed for authorization and authentication decisions.
Question 6: In a NestJS MQTT microservice, which option configures the broker URL at module registration?
- { transport: Transport.MQTT, options: { url: 'mqtt://...' } } (Correct answer)
- { transport: Transport.TCP, options: { host: 'mqtt://...' } }
- { transport: Transport.REDIS, options: { url: 'mqtt://...' } }
- { broker: 'mqtt://...' }
Correct answer: { transport: Transport.MQTT, options: { url: 'mqtt://...' } }
MQTT transport requires Transport.MQTT with an options object containing the broker url field.
Question 7: A business analyst wants non-technical stakeholders to understand API capabilities without reading code. What should you provide?
- Raw TypeScript source files
- An exported Swagger/OpenAPI JSON or YAML spec (Correct answer)
- Database entity diagrams
- Jest test reports
Correct answer: An exported Swagger/OpenAPI JSON or YAML spec
An exported OpenAPI spec can be imported into tools like Postman or rendered as human-readable documentation.
Which NestJS built-in class is used to emit custom events within the same application process?