- what purposes do middlewares serve in software development?
- What role do middlewares play in implementing security measures in software systems?
- What is middleware in the context of Express.js, and how does it enable developers to add functionality to web applications?
- What are some popular middleware libraries we use one developing in Express.js?
- What are the different types of middlewares express.JS can use? check Express.Js documentation.
Created
May 9, 2023 14:40
-
-
Save Kishimoto96/bb4f3d65aa87eb109afea0ae16ac3a93 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@eng.NUREDDIN @badrnasher @motaz99
middleware could be used to:
Log all requests and responses.
Authenticate users.
Generate CSRF tokens.
Validate request parameters
4. 1. Helmet — Increase HTTP Header Security
2. Cookie-parser — Parse Cookies
3. Passport — Access to Wide Range of Authentication Mechanisms
4. Morgan— Log HTTP Requests and Errors
5. CORS — Allow or Restrict Requested Resources on a Web Server
5. According to the official Express.js documentation, there are three types of middleware functions that can be used in an Express.js application:
Application-level middleware: These middleware functions are bound to an instance of the Express application, and can be used to perform actions on every request made to the application. Examples include logging, authentication, and error handling middleware.
Router-level middleware: These middleware functions are bound to an instance of an Express Router, and can be used to perform actions on every request made to a specific router or group of routes. Examples include authentication and validation middleware for specific routes.
Error-handling middleware: These middleware functions are used to handle errors that occur during request processing. They are defined with four parameters instead of three, the first one being an error object. Error-handling middleware must be defined after all other middleware and routes.