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.
Implementing middleware - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Implementing middleware
Now, let's understand how to implement middleware in NestJS. So first, let me create a folder, I'll name it as middleware. Inside this folder, I'll create a file called logging.middleware.ts. Here the dot middleware is the naming convention, but is not strictly necessary. It's more of a convention to make it clear that the file contains middleware code. Now inside the file, we will first provide the injectable decorator, as we are going to create a class and market as a middleware. And in order to use that class anywhere in the application, we give the injectable decorator. Let me create a class. I'll give export class and the class name LoggingMiddleware. Now in order to mark this class as a middleware, we will use an interface called NestMiddleware. So let me give implements NestMiddleware. So whenever we want to create a middleware, we always use the NestMiddleware interface. This interface offers a standard method that is used for specifically defining middleware logic, and that…
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)
-
-
-
-
-
-
-
-