Home  Express   List of mid ...

list of middlewares in express

In Express.js, middleware functions are functions that have access to the request object (req), the response object (res), and the next middleware function in the application's request-response cycle. They are essential for performing tasks such as parsing incoming requests, logging, handling sessions, authentication, etc.

Here are some common middleware in Express.js:

  1. express.json(): Parses incoming requests with JSON payloads. This middleware is responsible for parsing the req.body object.

  2. express.urlencoded(): Parses incoming requests with URL-encoded payloads. This middleware is used for parsing form data from <form> submissions.

  3. express.static(): Serves static files and assets such as images, CSS files, and JavaScript files.

  4. morgan: HTTP request logger middleware for logging request details.

  5. helmet: Helps secure Express apps by setting various HTTP headers.

  6. cors: Middleware for enabling Cross-Origin Resource Sharing (CORS) in Express apps.

  7. Session middleware:

    • express-session: Adds session support to store data between HTTP requests.
  8. Authentication middleware:

    • Examples include Passport.js middleware (passport.initialize() and passport.session()) for authentication strategies.
  9. Error-handling middleware:

    • Custom middleware functions to handle errors in Express applications (app.use(function(err, req, res, next) {...})).
  10. Compression middleware:

    • compression: Compresses HTTP responses to reduce the size of the response body.
  11. Body parsing middleware:

    • Apart from express.json() and express.urlencoded(), there are others like busboy-body-parser for handling multipart form data.
Published on: Jun 29, 2024, 03:05 PM  
 

Comments

Add your comment