Skip to content

Commit 40e9db5

Browse files
dpopp07heidemn-faro
andcommitted
docs: add v5 migration note for app.listen
Adds a note to the `migrating-5` guide alerting users that error events received by a server will now cause the callback argument in `app.listen` to be invoked. In Express 4, this was not the case and errors would be thrown. Resolves expressjs/express#6191 Signed-off-by: Dustin Popp <dustinpopp@ibm.com> Co-authored-by: M. Heide <66078329+heidemn-faro@users.noreply.github.com>
1 parent 9092d18 commit 40e9db5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

en/guide/migrating-5.md

+15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ You can then run your automated tests to see what fails, and fix problems accord
4545
<li><a href="#path-syntax">Path route matching syntax</a></li>
4646
<li><a href="#rejected-promises">Rejected promises handled from middleware and handlers</a></li>
4747
<li><a href="#express.urlencoded">express.urlencoded</a></li>
48+
<li><a href="#app.listen">app.listen</a></li>
4849
<li><a href="#app.router">app.router</a></li>
4950
<li><a href="#req.body">req.body</a></li>
5051
<li><a href="#req.host">req.host</a></li>
@@ -159,6 +160,20 @@ Details of how Express handles errors is covered in the [error handling document
159160

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

163+
<h4 id="app.listen">app.listen</h4>
164+
165+
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.
166+
For example:
167+
168+
```js
169+
const server = app.listen(8080, '0.0.0.0', (error) => {
170+
if (error) {
171+
throw error; // e.g. EADDRINUSE
172+
}
173+
console.log('Listening on ' + JSON.stringify(server.address()));
174+
});
175+
```
176+
162177
<h4 id="app.router">app.router</h4>
163178

164179
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.

0 commit comments

Comments
 (0)