Express 5.0 is still in an alpha release stage but there are a few changes coming that developers should be aware of. In this article we'll discuss the changes that the latest version of Express is going to bring.
Express 5 is not going to be really different from Express 4 however there will still be some breaking changes which means that code written using Express 4 may not work with Express 5.
Install Express 5
Installation is possible via npm by executing
npm i firstname.lastname@example.org.
Changes in Express 5
Let's now take a look at what changes will Express 5 bring - the changes can be categorised into removals, changes and improvements. There are a bunch of methods and properties that have been removed, some have a changed signature and some have seen improvements.
In Express 5 you cannot use
app.del() as it's been made deprecate. In order to specify a route for the HTTP DELETE method, use
The removal of this function was because since Express 4.11.0 the function is not supported at all anyway.
Pluralised method names
Three functions have received pluralised names, these are :
Retrieving parameter data is now only possible via directly accessing the submitted parameter name via
res.json(obj, status) and res.jsonp(obj, status)
res.json() could be used to send a JSON object, followed by an HTTP status code as a second parameter. From Express 5 the status needs to be sent via an appropriate function, followed by chained function call to
The same applies to
res.send(body, status) and res.send(status)
Just as explained earlier, the
res.send() method can no longer be used to send status codes. To send data and a status code use chained functions:
In order to only set the status, as of Express 5, use
Please note that for situations when we'd like to send a number as the data, we need to quote it or otherwise convert it to a string so that Express is not going to attempt to use the old function signature.
This method has been replaced with a camel-cased version:
app.router was removed in Express 4 and now it's back in Express 5 - as a reference to the base Express router.
In Express 5 the
req.host function maintains the port number as well (in Express 4 the same function incorrectly strips the port number)
We can now pass in
false as an option to this method in order to be able to implement our own query string parsing logic.
The render method is now enforcing asynchronous behaviour for all view engines.
Subscribe to Fullstack Developer Academy
Get the latest posts delivered right to your inbox