A middleware is a function which has access to the request and response objects (req, res) along with the next object. The next middleware function is able to make changes, end, and call the next middleware function using the request and response objects.
Simply put, a middleware is like a security guard that checks whether the user can have access to a particular server or not.
Morgan is a Node.js and Express middleware to log HTTP request and errors, and simplifies the whole process.
Morgan is similar to regular middlewares in terms of functionality. The one difference is that Morgan shows more detail when the server is running (ex. the time it took for the server to run).