With the start of 2017, it’s time to adapt these changes
ExpressJS 5.0 is in alpha release stage but I believe we’ll be adding it as a dependency in our
package.json files in matter of no time. This article gives some tips regarding the way we are writing code using this framework and how we should adapt the new changes even if we are using ExpressJS version 4.0.
I’ll start with most common thing such as
Express 5 no longer supports the signature
res.send , instead we should adapt using this method in this form:
We have to set the status code before sending the response object. This new version of
res.send is basically a chain of two methods:
With that mind, ExpressJS 5 deprecates
res.send(statusCode) method where
statusCode is the number representing the HTTP response header status code. To send just the statusCode, that is, without sending the response object, we can use
In similar manner, other methods that have been changed are:
res.json() --> res.status().json()
res.jsonp() --> res.status.jsonp()
Another notable method that is going to be deprecated in next version of ExpressJS is
res.sendfile() . Instead, we must adapt its new form, the camelCase one:
res.sendFile() which is already been supported by the ExpressJS versions later than
4.8.x . It comes with optional parameters that you can check them here.
Whether you are planning to use the alpha release of Express 5.0 or still going on with the latest versions of Express 4.0, I would suggest to start adapting these methods immediately.
The full list of changes or the official Express Migration Guide is to be found here.
Thank you for reading. If you find this post useful, please hit the 💚 button so this story can reach out to more readers. If you’d like to talk about it more, ping me on Twitter | Goodreads | Book Blog | Website | My articles on Hackernoon.com
Hacker Noon is how hackers start their afternoons. We’re a part of the @AMI family. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.
If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!