About Express 5

Table of contents

1 Overview

2. Changes in Express 5

2.1 List of Deprecated or Removed Content:

leading colon (:) in name in app.param(name, fn)

app.del()

app.param(fn)

plural method names

res.json(obj,status)

res.jsonp(obj,status)

req.param(name)

res.send(body,status)

res.send(status)

res.sendfile()

res.redirect(url, status)

2.2 Refactored content list:

2.3 Release Changelist:



 

1 Overview

Express 5.0 is still in beta, but here's a preview of what's changed in the release and how to migrate your Express 4 apps to Express 5.

Express 5 isn't much different from Express 4: the API change isn't as significant as going from 3.0 to 4.0. While the basic API remains the same, there are breaking changes; in other words, if you update an existing Express 4 program to use Express 5, the program may not work.

To install the latest beta and preview Express 5, enter the following command in the application root directory:

npm install [email protected] --save

The latest version is the beta.1 version, which is the first Express 5.0 beta, based on 4.17.2.

You can then run automated tests to see what fails and fix issues based on the updates listed below. After resolving test failures, run your app to see what went wrong. You'll immediately find out if your app uses any methods or properties that aren't supported.

2. Changes in Express 5

Below is a list of changes that will affect Express users (starting with the alpha 2 release). See the pull request for a list of all planned features.

2.1 List of Deprecated or Removed Content:

  • Leading colon in name parameter of app.param(name, fn)
  • app.of
  • app.param(fn)
  • req.acceptsCharset
  • req.acceptsEncoding
  • req.acceptsLanguage
  • res.json(obj, status)
  • res.json(status, obj)
  • res.jsonp(obj, status)
  • res.jsonp(status, obj)
  • req.param()
  • res.redirect(url, status)
  • res.send(body, status)
  • res.send(status)
  • res.send(status, body)
  • res.sendfile
  • res.vary()

If you use any of these methods or properties in your app, it will throw an error. Therefore, you need to change methods or properties in your app after updating to version 5.

leading colon (:) in name in app.param(name, fn)

app.param(name, fn)The leading colon (:) in the function name is a remnant from Express 3, and for backward compatibility, Express 4 supports it with a deprecation notice. Express 5 will silently ignore it and use the name parameter without a colon as a prefix.

If you follow the Express4 documentation for app.param app.param app.param this should not affect your code as it doesn't mention the leading colon.

Start modified version: 5.0.0-alpha.2 / 2015-07-06

app.del()

Express 5 no longer supports app.del()features. If this function is used, an error will be thrown. To register an HTTP DELETE route, use app.delete()a function.

Originally used delinstead of delete, since deleteis a reserved keyword in JavaScript. However, starting with ECMAScript 6, deleteand other reserved keywords can legally be used as property names.

Deprecated since version 3.6.0 

app.param(fn)

app.param(fn)The signature is used to modify app.param(name, fn)the behavior of the function. It's been deprecated since v4.11.0, and Express 5 no longer supports it at all.

Version 5.0.0-alpha.2 / 2015-07-06 Removed method

plural method names

The following method names have been pluralized. In Express 4, using the old method resulted in a deprecation warning. Express 5 no longer supports them:

req.acceptsCharset()Replace with req.acceptsCharsets().

req.acceptsEncoding()Replace with req.acceptsEncodings().

req.acceptsLanguage()Replace with req.acceptsLanguages().

Removed since 5.0.0-alpha.1 / 2014-11-06

res.json(obj,status)

Express 5 no longer supports signing res.json(obj, status). Then link it to res.json()the method like this: res.status(status).json(obj).

Removed since 5.0.0-alpha.1 / 2014-11-06

res.jsonp(obj,status)

Express 5 no longer supports signing res.jsonp(obj, status). Then link it to res.jsonp()the method like this: res.status(status).jsonp(obj).

Removed since 5.0.0-alpha.1 / 2014-11-06

req.param(name)

This potentially confusing and dangerous method of retrieving form data has been removed. Now you need to look specifically for the submitted parameter name in the req.params, req.bodyor object.req.query

Removed since 5.0.0-alpha.2/2015-07-06

res.send(body,status)

Express 5 no longer supports signing res.send(obj, status). Then link it to res.send()the method like this: res.status(status).send(obj).

Removed since 5.0.0-alpha.1 / 2014-11-06

res.send(status)

Express 5 no longer supports signatures res.send(status)where statusis a number. Instead, use res.sendStatus(statusCode)functions, which set the HTTP response header status code and send the text version of the code: "Not Found", "Internal Server Error", etc. If you need to res.send()send a number with a function, quote the number to convert it to a string so that Express doesn't interpret it as trying to use an old unsupported signature.

Removed since 5.0.0-alpha.1 / 2014-11-06

res.sendfile()

In Express 5, res.sendfile()functions have been replaced by camel-style versions res.sendFile().

Removed since 5.0.0-alpha.1 / 2014-11-06

res.redirect(url, status)

Express 5 no longer supports signing res.redirect(url, status). Instead, set the state, then link it to res.send()the method like this: res.status(status).send(obj).

Removed since 5.0.0-alpha.6 / 2014-11-06

res.vary()

Removed since 5.0.0-alpha.3 / 2017-01-28

2.2 Refactored content list:

  • Move the router to its own repository

Separate the routing module into a warehouse, the address is as follows:

GitHub - pillarjs/router: Simple middleware-style router

2.3 Release Changelist:

  • Add support for Promises in all handlers
  • Returns app.router, which is usually used to call the router directly
  • Make the query parser option default to "simple"
  • Make bodyParser.urlencoded default to 'simple'
  • Make req.host actually return the host, which previously returned the hostname
  • req.queryShould be a getter, not added via middleware
  • New path matching syntax
  • Remove Express 3.x middleware error stubs
  • Use mime-types instead of mime
  • Use absolute paths to detect modules

 

Guess you like

Origin blog.csdn.net/u014388408/article/details/132042198