0 votes
in JavaScript by
Explain about the Middleware in Express.Js?

1 Answer

0 votes
by

Middleware refers to reusable components that can be plugged into an Express application. Middleware consists of functions that handle HTTP requests, such as the one we would pass to Node's native http.createServer function. A middleware component can add features by manipulating the request and response objects and then send the response to the client or pass control to the following middleware in the stack.

To load a middleware into an Express application, we call the app.use() method. The app.use() method takes an optional path parameter as the first argument, which is useful if we want to mount certain functionalities to an endpoint. When using the path parameter, the middleware will be executed only if the URL matches that path. Practical use cases include serving static assets under the /public path or loading special middleware for an admin path

...