How to create your own middleware in express js

In the world of web development, the Middleware functions are used to gain access control over the request object (req) and the response object (res). Apart from that, the middleware function has the power to access the next function of the request-response life cycle. Here in this step-by-step guide, we have elaborated how to create Node.JS Middleware and Express Middleware.
index.js

var express = require('express');
var path = require('path');
var app = express();

const myMiddleware = (req, res, next) => {
     console.log('middleware call');
}

app.use(myMiddleware);
app.listen(3000);

Leave a Reply