How can you define multiple route paths for a single controller method in NestJS?
By using the @Routes() decorator
@Routes()
By defining multiple methods for each path
By using an array of strings as the route path
It's not possible to have multiple paths for one method
How do you access the request body in a NestJS controller?
Through the context object
context
Accessing request.data
request.data
Using req.body
req.body
Using the @Body() decorator
@Body()
How do you inject a provider from a different module in NestJS?
By accessing the global NestJS container.
By using the @Inject() decorator and specifying the provider's class name.
@Inject()
By importing the module containing the provider into the module where you need it.
By creating a new instance of the provider using its constructor.
Which HTTP method does the @Post() decorator handle?
@Post()
GET
POST
PUT
DELETE
What is a key advantage of using NestJS over plain Express.js for building Node.js applications?
NestJS directly interacts with the database, eliminating the need for ORMs
NestJS enforces a strict project structure and uses TypeScript for better code organization
NestJS is more lightweight and has fewer dependencies
NestJS is faster for handling HTTP requests
In a typical NestJS project structure, which directory commonly houses the application's source code?
/public
/node_modules
/src
/dist
How do you apply an exception filter globally in a NestJS application?
By manually invoking the filter within each controller method.
By using the useGlobalFilters() method in the app.module.ts file.
useGlobalFilters()
app.module.ts
By decorating the controller class with the filter.
By adding the filter class to the providers array of a module.
providers
What is the purpose of the @Module() decorator?
@Module()
To define a route handler for a specific HTTP method.
To mark a class as a database entity.
To define a unit test case.
To define a module, which acts as a container for other NestJS components.
Which decorator is used to define a controller in NestJS?
@Injectable()
@Controller()
@Component()
What is the purpose of dependency injection in NestJS?
To provide a mechanism for creating and injecting dependencies into classes.
To handle errors gracefully.
To manage database connections.
To define the application's routing logic.