5 Express Middleware Libraries Every Developer Should Know!

5 Express Middleware Libraries Every Developer Should Know!

1. Cookie-parser — Parse Cookies

Cookie-parser is a middleware that transfers cookies with client requests.

Cookie-parser uses the req.cookies property to access Cookie data. After parsing, the req.cookies object holds cookies sent by request in JSON format.

It is capable of parsing both unsigned and signed cookies.

Features of Cookie-parser

  • The decode function is there to decode the value of the cookie.
  • Handle cookie separation and encoding.
  • Can enable signed cookie support by passing a secret string.
  • supports special "JSON cookies" with JSON.parse.

2.Passport — Access to Wide Range of Authentication Mechanisms

Passport is a simple unrobustive authentication middleware for Node.js.

It consists of a comprehensive set of authentication mechanisms known as "strategies." Those strategies support authentication using either a username and password or Facebook, Twitter, and more. Passport allows the developers to make application-level decisions and choose the best strategy maximizing its flexibility.

Features of Passport

  • 500+ authentication strategies.
  • Extremely easy to integrate into an application.
  • Single Sign-on with OpenID and OAuth.
  • Supports persistent sessions.
  • Lightweight code base.
  • Let you implement custom strategies.

3. Morgan— Log HTTP Requests and Errors

Morgan is an HTTP request logger middleware for Node.js typically used for Express apps.

It streamlines the process by generating logs for each API request and error. The best fact is that you can utilize a predefined format or design one from scratch, depending on your requirements.

Features of Morgan

  • It Logs the HTTP requests along with some other information. You can also configure what you choose to log.
  • Very helpful in debugging and also if you want to create Log files.

Morgan has over 12.88 million NPM downloads per month and 6.8K GitHub stars.


4. CORS — Allow or Restrict Requested Resources on a Web Server

CORS is a node.js package that provides a Connect/Express middleware for enabling CORS with a variety of options.

CORS stands for Cross-Origin Resource Sharing. Without prior consent, it prevents other websites or domains from accessing your web resources directly from the browser.

Features of CORS

  • Supports GET, POST, or HEAD HTTP methods.
  • Allows web programmers to use regular XMLHttpRequest, which handles errors better.
  • Allows websites to parse responses to increase security.

CORS has over 6 million NPM downloads per week and 5.2K GitHub ratings.


5. Helmet — Increase HTTP Header Security

Helmet helps you secure your Express apps by setting various HTTP headers.

It is a quick and straightforward way to create an additional layer of security by switching from Express default headers to more standard ones.

Features of Helmet

  • A Connect-style middleware.
  • It secures your Node.js application from common security vulnerabilities such as clickjacking, implementation of strict HTTP, and download options for vulnerable browsers such as IE8.
  • Instructs browsers to use HTTPS instead of insecure HTTP.
  • In addition, it comes with a way to allow web applications to isolate their origins with Origin-Agent-Cluster header.
  • Has some browser-specific configuration options (helmet.ieNoOpen()for Internet Explorer 8).

Helmet has over 1 million NPM downloads per week and 8.6K GitHub ratings.


#dev #mern #nodejs #node



要查看或添加评论,请登录

Vignesh H E的更多文章

社区洞察

其他会员也浏览了