2ex 中文文档教程

发布于 6年前 浏览 28 项目主页 更新于 3年前

2ex (pronounced 2X)

NPM 版本 NPM 下载 构建状态js- standard-style

用于设置 Express 应用程序的半固执己见的框架。

Install

$ npm install --save 2ex

Usage

const createApp = require('2ex')

const runApp = createApp((app, opts = {}) => {
  // Handle app errors
  app.on('error', console.error)

  // Load in your routes
  app.get('/', (req, res) => {
    res.send(`Hello ${opts.message}!`)
  })
})

// Start the app
runApp({
  port: 8080,
  message: 'World'
}).then(({ app, server }) => {
  const addr = server.address()
  console.log(`Server started at http://${app.get('host')}:${addr.port}`)
})

What does it do?

这个包设置了在生产中运行 Express 应用程序的通用要求 目标是减少应用程序中的样板文件。 以下是其中一些内容的列表:

  • Uses next gen Express (5.0.0-alpha.7 at the time of publishing this)
  • See the GitHub PR for 5.0 for details
  • New and improved path-to-regex
  • Router with basic promise support
  • Express app settings
  • Remove x-powered-by header
  • Sets query string parsing to simple (faster, more secure, planned default for 5.0)
  • Set process title (nice for identifying your server process)
  • Catch, report and exit on uncaughtException and unhandledRejection
  • Handle and report server clientErrors
  • Parses JSON bodies
  • Parses cookies (off by default, turn on by passing options.parseCookies

2ex (pronounced 2X)

NPM VersionNPM DownloadsBuild Statusjs-standard-style

A semi-opinionated framework for setting up Express apps.

Install

$ npm install --save 2ex

Usage

const createApp = require('2ex')

const runApp = createApp((app, opts = {}) => {
  // Handle app errors
  app.on('error', console.error)

  // Load in your routes
  app.get('/', (req, res) => {
    res.send(`Hello ${opts.message}!`)
  })
})

// Start the app
runApp({
  port: 8080,
  message: 'World'
}).then(({ app, server }) => {
  const addr = server.address()
  console.log(`Server started at http://${app.get('host')}:${addr.port}`)
})

What does it do?

This package sets up common requirements for running an Express app in production with the goal of reducing boilerplate in your applications. Here is a list of some of those things:

  • Uses next gen Express (5.0.0-alpha.7 at the time of publishing this)
  • See the GitHub PR for 5.0 for details
  • New and improved path-to-regex
  • Router with basic promise support
  • Express app settings
  • Remove x-powered-by header
  • Sets query string parsing to simple (faster, more secure, planned default for 5.0)
  • Set process title (nice for identifying your server process)
  • Catch, report and exit on uncaughtException and unhandledRejection
  • Handle and report server clientErrors
  • Parses JSON bodies
  • Parses cookies (off by default, turn on by passing options.parseCookies
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文