Search code examples
nestjs

how to decide to use which middleware in nest.js


As title.
I am learning Nest.js.
there are many provider in nest ,
such as middleware、pipe、guard、interceptor.
For me ,they are middleware.
How to distinguish their usage scenario.
Thanks all.


Solution

  • each one has its specific usage

    for example :

    we use Gards when we want to give acces conditions to an end point or a global controller for example we want the service "update user" to be only called by admins (user with role Admin)

    we use Pipes to transform the input data to a specific form or to validate some inputs

    learn more here in nestJs doccumentation