Hi all,
Picking up from the (now closed) thread "Is the new express library (version 5) usable with NodeRED?" and issue #5097.
In #5097 knolleary said the ideal would be "a compatibility mode available that would allow us to upgrade, but retain some of the removed v4 APIs with deprecation warnings", because of the large ecosystem of nodes built on Express 4. I've built that, on top of moving core to Express 5.3, and I'd like your view before raising a PR.
What the branch does (3 commits against current main):
- Moves core and the core nodes to Express 5.3. Wildcard and inline-regex routes are rewritten for the new path syntax, Express 4's "extended" query parser is kept as the default (so
msg.req.querystill expandsa[b]=1), and HTTP In finds the router on either Express 4 or Express 5 hosts. - Fixes the "stream is not readable" error reported in #5097 when Node-RED is embedded in an Express 5 app that parses bodies itself. I reproduced it (deploy returned 500); with the fix, deploys and HTTP In work.
- Adds an Express 4 compatibility layer on RED.httpNode and RED.httpAdmin. It translates unnamed wildcards (restoring
req.params[0]), optional:param?routes,res.send(status),res.json(obj, status),res.sendfile(),req.param(),app._routerand writes toreq.query. Each one logs a one-time deprecation warning naming the route or API. It can be turned off withexpress4Compatibility: false. Users' existing HTTP In URLs like/files/*keep working through it too.
How much of the ecosystem this affects: I scanned the 204 most-downloaded community packages. 21 use something Express 5 breaks. 13 of those register a route Express 5 refuses, so the whole module fails to load. That includes node-red-dashboard, node-red-node-ui-table and node-red-contrib-sun-position, nearly all with the same pattern: RED.httpAdmin.get('/my-node/js/*', ...) plus res.sendFile(req.params[0]). The rest use res.send(status), app._router or write to req.query.
I installed six of them on the branch. With the compatibility layer off, five fail to load. With it on, all six load and serve their files, and the log tells the authors what to change. I'm happy to share the full list and how I scanned.
Tests: full suite passes apart from failures that need ssh-keygen, IPv6 or network access in my environment; 19 new tests for the new code.
Questions:
- Is this the kind of compatibility mode you had in mind?
- Which branch and release would you want it for:
dev, aimed at the next major version? - How long should the compatibility layer stay before it's removed or turned off by default?
Happy to open a draft PR so you can look at the code, and to adjust any of it.