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 global pipes

Implementing global pipes

Until now, we have seen various ways of applying pipes that is on the controller level and the parameter level. There is another way and a much better alternative to apply the pipes and that is applying the pipe at a global level. Global pipes keep a watch on the incoming data across the entire application. Rather than applying pipes individually to each route or parameter, global pipes provide a centralized way to handle common tasks like validation, sanitization, or transformation. Let's see how to apply a global pipe. So here in this example, we have applied the validation pipe and a custom phone auth pipe. Now let's say that we want to keep the custom pipe for the post route handler only and want the validation pipe on the entire application. In that case, inside the main TS file, which is the entry point of any nest application, I'll give the app dot use global pipes method. The useGlobalPipes is a built-in method provided by NestJS, whose purpose is to set up global pipes that…

Contents