Node js express middleware Next

Parth Padhiar
2 min readNov 30, 2020

Middleware functions are functions that have access to the request object (req), the response object (res), and the next function in the application’s request-response cycle. The next function is a function in the Express router which, when invoked, executes the middleware succeeding the current middleware.

Example

  1. Here first called logger function because it called before the api.

Output:

2. Here, the logger function is not called because it placed after the api and there is no next exist in api.

Output:

3. Here we have added next in api , therefor the logger function is called. Thats what next do, if there is any middleware after api and we want to call it so we use next so if there is any middleware function then it will run.

Output:

4. Here, if we pass false in params then it will show no Auth.

Output:

--

--