Skip to content

Instantly share code, notes, and snippets.

@Kishimoto96
Created May 9, 2023 14:40
Show Gist options
  • Save Kishimoto96/bb4f3d65aa87eb109afea0ae16ac3a93 to your computer and use it in GitHub Desktop.
Save Kishimoto96/bb4f3d65aa87eb109afea0ae16ac3a93 to your computer and use it in GitHub Desktop.

Discussion questions about middlewares

  1. what purposes do middlewares serve in software development?
  2. What role do middlewares play in implementing security measures in software systems?
  3. What is middleware in the context of Express.js, and how does it enable developers to add functionality to web applications?
  4. What are some popular middleware libraries we use one developing in Express.js?
  5. What are the different types of middlewares express.JS can use? check Express.Js documentation.
@motaz99
Copy link

motaz99 commented May 9, 2023

@eng.NUREDDIN @badrnasher @motaz99

  1. Middleware is a term used to describe software that sits between different applications or systems, providing a communication layer that allows them to interact with each other. In software development:
    1. Communication
    2. Integration
    3. Security:
    4. Scalability
  2. Middlewares can provide security measures such as authentication, authorization, encryption, and auditing, which can help protect data and applications from unauthorized access or attack. They can also act as a security layer by enforcing security policies and access controls between different components of the system, reducing the risk of malicious activity. Additionally, middlewares can enable secure communication between different systems or applications, providing a standardized way to encrypt and decrypt data and ensuring that data is not compromised during transit.
  3. Middleware is a function that takes an HTTP request and an HTTP response as input, and returns an HTTP response. Middleware can be used to add functionality to web applications by intercepting requests and responses before they are handled by the application's code.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment