Express enters Beta 1, proving the project is still alive

; Date: Thu Feb 17 2022

Tags: Node.JS

Express is the most popular web application framework for Node.js, even while its development has seemingly stagnated for years. Work on the Express repository is very slow, and the Express 5.x release has been promised for years; for example 5.alpha.1 was released in November 2014. But if you look under the covers, there is significant work happening in Express sub-projects.

On February 14, 2022, the Express team (primarily Doug Wilson) released version 5.0.0-beta-1, released to the npm/yarn repository, marking it as the next release. That label is meant to tell those of us looking to try out the next greatest version of Express should try the 5-beta-1 release.

It is Express v5 which promises to supply the long-awaited support for asychronous handler functions, among other changes.

It's important to note that at the same time that 5.0-beta-1 has been released, the 4.x branch has begun to have activity. Just today, 4.17.3 was released, and two months ago 4.17.2 was released. Together these releases are a nice change considering the previous 4.x branch release (4.17.1) was three years ago, and that the previous 5.x branch release (5.0-alpha-8) was two years ago.

The Express package is seeing sustained/growing download traffic, according to its page on npmjs.com. Weekly downloads are well over 24 million, and growing steadily, with 4.17.2 (9,865,506 downloads) and 4.17.1 (12,526,431 downloads) receiving the most activity.

That story, that the Express project is moving slowly, but despite that is being heavily used, is testament to how solid, reliable and useful is Express.

A quick scan of the download statistics of other web frameworks (as reported on npmjs.com) shows Express with 5-10x the number of downloads of the nearest competitor.

For status - when will version 5 be finished - (github.com) see the pull request (which was started in July 2014). It looks like there isn't much left to do. This pull release began receiving a lot of activity in late January 2022, which looks like preparation for a release. If you're taking a look, a January 2020 comment by Wesley Todd is an apt description of the project status - that the project team has wanted to finish Express v5 for a long time, but nobody is paid to work on Express, and they're all very busy.

XKCD #2347

That image is oh so very true - there are hundreds of critical open source projects, that are receiving little funding, and are a labor of love of one or a handful of people, which huge corporations use in applications that reap megabucks.

To better understand what that means, start with (github.com) the graph of commits to the master branch of the Express repository

Express contributors - source GitHub

This shows that "tj" (TJ Holowaychuk) started Express over 10 years ago, and did a lot of work, and then in 2014 his contributions trailed off while Doug Wilson's contributions took off. But, it also shows that contributions overall have been minimal over the last several years, other than a recent flurry.

But, this is only the surface of the picture for Express. The charts here are to the master branch. The (github.com) 5.0 branch is receiving sustained activity, for example. But, wait, thats not all.

The expressjs/express repository is only part of the Express project. There are other modules which are involved, which are receiving sustained activity: (github.com) express/body-parser, express/session, (github.com) express/serve-static, express/multer, (github.com) express/cors, express/cookie-session, (github.com) express/cookie-parser, express/morgan, (github.com) express/serve-index, express/compression ...etc... In some cases portions of Express is derived from projects under the PillarJS umbrella - see (pillarjs.github.io) http://pillarjs.github.io/ - These project repositories are also receiving sustained activity, and many are maintained by Doug Wilson.

In other words, if you were to only look at the release activity of the Express package, the Express project looks stagnant. But, it is a larger ecosystem of packages than just the Express project, and the sub-projects are receiving continued attention.

The other thing to notice is that Doug Wilson is the primary contributor to most of these packages. If Doug Wilson weren't taking care of things, where would Express be? Given its high popularity, why aren't there more people contributing to Express?

Getting started with Express v5

Theoretically the "Beta" label means that Express v5 is ready for testing by folks outside the Express team. There is a traditional meaning for "Alpha" or "Beta" stage in product development. Namely, Alpha releases are primarily for the project team, and selected partner organizations, where Beta releases are still for testing but by a broader set of the population.

Therefore, web application authors who use Express should perk up and try their application with Express v5.

What one does to try Express v5 is described in the migration guide: (expressjs.com) https://expressjs.com/en/guide/migrating-5.html

It starts by switching your Express dependency to using 5.0.0-beta-1 such as this way:

$ npm install express@>=5.0.0-beta.1 --save

Then, you run your tests and fix any bugs.

Besides the migration guide, there is API documentation: (expressjs.com) https://expressjs.com/en/5x/api.html

On a brief skim it appears the API is largely the same as with Express v4. But, the website clearly says the Express v5 documentation is a work in progress.

There is one big change which appears to not break compatibility, but gives us a much needed long-awaited feature. If you look closely at the Express 5 pull request, one issue (that has already been solved) is for all handlers to support Promises. This was tracked in (github.com) issue 2259 and was released through the pillarjs/router repository. Which is a demonstration that important work on Express is happening outside the expressjs/express repository.

Going by the documentation on pillarjs/router (for the 2.0 branch), middleware functions can now handle Promise's:

The function can optionally return a Promise object. If a Promise object is returned from the function, the router will attach an onRejected callback using .then. If the promise is rejected, next will be called with the rejected value, or an error if the value is falsy.

This is a big thing, since Express has long lacked support for async/await functions. While we could use such functions, we had to jump through extra hoops. This new behavior eliminates those hoops.

This appears to mean we can now make this change:

// OLD CODE
router.get('/error_route', async function (req, res, next) {
    try {
        // run some async code
    } catch (e) {
        next(e);
    }
});

// NEW CODE
router.get('/error_route', async function (req, res, next) {
    // run some async code
});

By being an async function, it returns a Promise triggering the behavior described here. Going by this, the router object attaches .then(onRejected) and .catch(errorHandler) to the promise, neatly passing either condition to the routing system. It means our handler functions can now perform asynchronous operations, throwing errors in a natural way, and the Express router will automatically handle the status whether it is an error or success.

About the Author(s)

(davidherron.com) David Herron : David Herron is a writer and software engineer focusing on the wise use of technology. He is especially interested in clean energy technologies like solar power, wind power, and electric cars. David worked for nearly 30 years in Silicon Valley on software ranging from electronic mail systems, to video streaming, to the Java programming language, and has published several books on Node.js programming and electric vehicles.

Books by David Herron

(Sponsored)