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 interceptors

Applying global interceptors

Just like the pipes and guards, interceptors can either be controller scoped, method scoped, or global scoped. Applying interceptors globally ensures that the interceptor is applied on every single route handler in the application. There are two ways to apply global interceptors. First way is to configure the interceptor inside the app module file. So, let me open the app module file and inside the providers array, I will give the curly braces that is known as the providers object. We have already seen what is the use of providers object in the previous section. Inside this object, I will give the provide property which takes a token value predefined by NestJS. As we want to register the interceptor globally, I will give the token app underscore interceptor and along with the token we also have to specify the interceptor class by using the use class property and the class name that is AuthInterceptor. That's it. So, this AppInterceptor is special token that NestJS recognizes for…

Contents