What's new in Express 5?
Older Article
This article was published 9 years ago. Some information may be outdated or no longer applicable.
Express 5.0 is still in alpha, but there are changes coming that you should know about. Let’s walk through them.
Express 5 won’t look radically different from Express 4. But it does carry breaking changes, meaning code written for Express 4 might not work with Express 5.
Install Express 5
Install via npm: npm i express@5.0.0-alpha.2.
Changes in Express 5
The changes fall into three buckets: removals, changed signatures, and improvements. Some methods and properties have been dropped, some behave differently, and some have gotten better.
app.del()
Gone. If you need a route for the HTTP DELETE method, use app.delete().
app.param(fn)
Removed because it hasn’t been supported since Express 4.11.0 anyway.
Pluralised method names
Three functions now have pluralised names:
req.acceptsCharsets()req.acceptsEncodings()req.acceptsLanguages()
req.param(name)
You can no longer pull parameter data this way. Access it directly through req.params, req.body or req.query.
res.json(obj, status) and res.jsonp(obj, status)
Previously, res.json() accepted a JSON object and an HTTP status code as a second parameter. From Express 5, you set the status separately and chain: res.status(statusCode).json(obj).
Same applies to res.jsonp.
res.send(body, status) and res.send(status)
Same story. res.send() can no longer carry status codes. Send data with a status using chained calls: res.status(statusCode).send(body).
To set only the status, use res.sendStatus(statusCode).
One thing to watch: if you want to send a number as the response body, quote it (or convert it to a string). Otherwise Express will try to interpret it as a status code using the old signature.
res.sendfile()
Replaced with the camel-cased version: res.sendFile().
app.router
This was removed in Express 4 and is now back in Express 5 as a reference to the base Express router.
req.host
In Express 5, req.host keeps the port number intact. Express 4 incorrectly stripped it.
req.query
You can now pass false as an option to plug in your own query string parsing logic.
res.render
The render method now enforces asynchronous behaviour for all view engines.