Put in order · NestJS course · Module 2: Routing and Request Lifecycle

Registering Middleware in a Module

Order the steps for registering middleware in NestJS from first to last:

Items to put in order

  • Specifying routes using .forRoutes()
  • Calling consumer.apply(Middleware) in the configure() method
  • Implementing the NestModule interface in the module class
  • Creating a middleware class with @Injectable()
Show the answer

Correct order:

  1. Creating a middleware class with @Injectable()
  2. Implementing the NestModule interface in the module class
  3. Calling consumer.apply(Middleware) in the configure() method
  4. Specifying routes using .forRoutes()