From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Registering a middleware - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Registering a middleware
Now, let's see how to register a middleware. Any middleware defined within NestJS has to be registered with a specific module. Right now, as we do not have any module other than the app module, let's register the middleware inside it. So inside the app module TS file, we have the app module class. This is where we have to configure the middleware. And to do so, we have to make use of an interface called nest module. This interface allows us to provide additional configuration to a module like configuring middleware. This interface provides a method called configure, which is used to register a middleware. And as you can see, it receives a middleware consumer parameter, which allows the module to configure middleware for incoming requests. The middleware consumer is actually a helper class that provides few built-in methods to be used with middleware. So the configure method is part of the Nest module interface and is implemented within module class, and it takes a middleware consumer…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Introduction to Nest middlewares3m 46s
-
(Locked)
Implementing middleware3m 45s
-
(Locked)
Registering a middleware5m 20s
-
(Locked)
Route-specific middleware5m 48s
-
(Locked)
Assignment: Checking Content-Type with middleware4m
-
(Locked)
Handling route wildcards3m 19s
-
(Locked)
Middleware for specific route handlers4m 38s
-
(Locked)
Excluding routes3m 49s
-
(Locked)
Controller-driven route middleware2m 15s
-
(Locked)
Understanding functional middleware4m 26s
-
(Locked)
Applying multiple middlewares6m 51s
-
(Locked)
Applying global middlewares3m 52s
-
(Locked)
Assignment: Password encryption middleware10m 19s
-
(Locked)
-
-
-
-
-
-
-
-