当前位置: 首页 > 文档资料 > Express 中文文档 >

Express 中间件

优质
小牛编辑
116浏览
2023-12-01

Express middleware

The Express middleware modules listed here are maintained by the Expressjs team.

Middleware moduleDescriptionReplaces built-in function (Express 3)
body-parserParse HTTP request body. See also: body, co-body, and raw-body.express.bodyParser
compressionCompress HTTP responses.express.compress
connect-ridGenerate unique request ID.NA
cookie-parserParse cookie header and populate req.cookies. See also cookies and keygrip.express.cookieParser
cookie-sessionEstablish cookie-based sessions.express.cookieSession
corsEnable cross-origin resource sharing (CORS) with various options.NA
csurfProtect from CSRF exploits.express.csrf
errorhandlerDevelopment error-handling/debugging.express.errorHandler
method-overrideOverride HTTP methods using header.express.methodOverride
morganHTTP request logger.express.logger
multerHandle multi-part form data.express.bodyParser
response-timeRecord HTTP response time.express.responseTime
serve-faviconServe a favicon.express.favicon
serve-indexServe directory listing for a given path.express.directory
serve-staticServe static files.express.static
sessionEstablish server-based sessions (development only).express.session
timeoutSet a timeout period for HTTP request processing.express.timeout
vhostCreate virtual domains.express.vhost

Additional middleware modules

These are some additional popular middleware modules.

Warning: This information refers to third-party sites, products, or modules that are not maintained by the Expressjs team. Listing here does not constitute an endorsement or recommendation from the Expressjs project team.

Middleware moduleDescription
cls-rtracerMiddleware for CLS-based request id generation. An out-of-the-box solution for adding request ids into your logs.
connect-image-optimusOptimize image serving. Switches images to .webp or .jxr, if possible.
express-debugDevelopment tool that adds information about template variables (locals), current session, and so on.
express-partial-responseFilters out parts of JSON responses based on the fields query-string; by using Google API’s Partial Response.
express-simple-cdnUse a CDN for static assets, with multiple host support.
express-slashHandles routes with and without trailing slashes.
express-stormpathUser storage, authentication, authorization, SSO, and data security.
express-uncapitalizeRedirects HTTP requests containing uppercase to a canonical lowercase form.
helmetHelps secure your apps by setting various HTTP headers.
join-ioJoins files on the fly to reduce the requests count.
passportAuthentication using “strategies” such as OAuth, OpenID and many others. See http://passportjs.org/ for more information.
static-expiryFingerprint URLs or caching headers for static assets.
view-helpersCommon helper methods for views.
sriracha-adminDynamically generate an admin site for Mongoose.

For more middleware modules, see http-framework.