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.
Applying global middlewares - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Applying global middlewares
Now, let's see how to apply middlewares globally. There are basically two ways we can apply any middleware globally in NestJS. Let's check it out. I have middleware here, which we implemented in the previous lecture. To apply this method globally, I'll go to the app module file, where we have defined the for routes method. And inside it, I'll give the path property, setting a wildcard route and method property where I give the request method dot all. The all represents all the HTTP methods that is get, put, patch, post, delete, etc., thus setting the middleware globally. So if I try to make the request in the postman, we already have the request body here. Let me make the post request and it works perfectly. So currently the middleware is globally applied. Now the second way is a more familiar way. If you have experience dealing with middleware in Express, that is by using the app.use method. What I'll do here, I'll comment on this apply method, and we don't need any consumer here in…
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)
-
-
-
-
-
-
-
-