Understanding middleware in Node.js

Think of middleware as a group of filters. Every request to your server passes through these filters one by one. Each filter performs a specific task. These tasks can be cooking parsing, authentication etc. There are written modules (middlewares) that you can use or you can write your own.

Note:
Since each request passes through each filter, you have to make sure that they are placed in the code in the correct order. For example a cookie parser should be run before a session handler.

All the dependencies we have installed are going to be used as middlewares and integrated in our code. This task will be done within the config module.

Leave a Reply