Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add v5 migration note for app.listen #1705

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions en/guide/migrating-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ You can then run your automated tests to see what fails, and fix problems accord
<li><a href="#path-syntax">Path route matching syntax</a></li>
<li><a href="#rejected-promises">Rejected promises handled from middleware and handlers</a></li>
<li><a href="#express.urlencoded">express.urlencoded</a></li>
<li><a href="#app.listen">app.listen</a></li>
<li><a href="#app.router">app.router</a></li>
<li><a href="#req.body">req.body</a></li>
<li><a href="#req.host">req.host</a></li>
Expand Down Expand Up @@ -159,6 +160,20 @@ Details of how Express handles errors is covered in the [error handling document

The `express.urlencoded` method makes the `extended` option `false` by default.

<h4 id="app.listen">app.listen</h4>

In Express 5, the `app.listen` method will invoke the user-provided callback function (if provided) when the server receives an error event. In Express 4, such errors would be thrown. This change shifts error-handling responsibility to the callback function in Express 5. If there is an error, it will be passed to the callback as an argument.
For example:

```js
const server = app.listen(8080, '0.0.0.0', (error) => {
if (error) {
throw error // e.g. EADDRINUSE
}
console.log(`Listening on ${JSON.stringify(server.address())}`)
})
```

dpopp07 marked this conversation as resolved.
Show resolved Hide resolved
<h4 id="app.router">app.router</h4>

The `app.router` object, which was removed in Express 4, has made a comeback in Express 5. In the new version, this object is a just a reference to the base Express router, unlike in Express 3, where an app had to explicitly load it.
Expand Down
Loading