Although Express 5 is not very different than Express 4.0 but you might get some breaking points which you need to consider changing after upgrading.
Installing Express 5
Since Express 5 is still in the alpha release stage, you need to install it using the following command
npm install firstname.lastname@example.org --save
Learn More At : Creating your first Application in Express
If you do not which is the latest alpha release of Express.js, you can go to Express.js Github Repository and find out the latest Pre-release as of that day as shown below.
Changes in Express 5 as of Alpha 3 release
The changes which you need to do in Express 4 before migrating to Express 5 are :
//In Alpha 3
- Change res.json(obj, status) to res.status(status).json(obj) // Signature change
- Change res.jsonp(obj, status) to res.status(status).jsonp(obj) // Signature change
- res.vary() accepts a field name as an argument
// In Alpha 2
- Removed app.param(fn)
- Now use req.params, req.body or req.query to get form data instead of req.param()
- res.render callback becomes async
- ':' charcter in name for app.param(name, fn) has been removed
- use router module for routing
- use path-is-absolute module for absolute path detection
// In Alpha 1
- Change app.del to app.delete // Function name change
- Change req.acceptsCharset to req.acceptsCharsets // Function name changes
- Change req.acceptsEncoding to req.acceptsEncodings // Function name changes
- Change req.acceptsLanguage to req.acceptsLanguages // Function name changes
- Change res.send(body, status) to res.send(status, body) // Signature change
- Change res.sendfile to req.sendFile // Function name changes
- Removed express.query
- req.host gets hostname:port, to get only hostname use req.hostname
- req.query is now a getter and not a plain property.
- Added app.router as a reference to the base router
Express 5 is still in alpha so there are bound to be changes. I will try to keep updating this post as the updates are rolled out.
Please Like and Share CodingDefined.com blog, if you find it interesting and helpful.