Upgrading Express 4 to 5: the changes that break apps
Express 5 needs Node.js 18 or higher, and a handful of changes make an Express 4 app crash, return different data or stop matching routes. This guide lists the ones that most often bite, what to search for, and the fix. Every claim comes from the official Express 5 migration guide, linked at the end.
req.queryis now a getter: code that assigns to it fails.req.bodyisundefinedwhen no body parser ran, not{}.- Route paths use path-to-regexp 8: bare
*wildcards, the?optional marker and regex characters in paths no longer work. - Several methods and call forms are removed:
app.del(),req.param(),res.send(status),res.json(obj, status),res.redirect('back'),res.sendfile()and more. - Rejected promises and thrown errors in async handlers now reach your error middleware.
1. req.query is read-only
In Express 5, req.query is a getter, so it is no longer writable. The default query parser also changed from extended to simple. Code like this breaks:
app.get('/search', (req, res) => {
req.query.page = 1; // not possible in Express 5
});
What to search for: any assignment to req.query, or Object.assign(req.query, ...). Validation and sanitising middleware are the usual culprits, because they often overwrite the query with a cleaned copy. Fix: leave req.query alone and put the cleaned value somewhere else, for example a new property on res.locals or on a local variable your handler reads.
If your app depends on nested query strings such as ?a[b]=1, check what the new default parser gives you for them. The query parser app setting accepts "simple" (the Express 5 default, based on Node's querystring), "extended" (based on qs), false or your own function, for example app.set('query parser', 'extended').
Where tests may not help: in our own test upgrades of open-source Express projects, a fix of this kind was not covered by the project's tests, because they passed plain mock request objects that never hit the getter. A green test run does not prove this one. Read the code.
2. req.body can be undefined
Express 5 returns undefined for req.body when the body has not been parsed. Express 4 returned {}.
app.post('/user', (req, res) => {
console.dir(req.body);
// Express 4 => {}
// Express 5 => undefined
});
What to search for: reads such as req.body.name in routes where the parser (express.json(), express.urlencoded()) is not mounted before the route, or where the request had no body or a content type the parser skips. Fix: mount the parser before the route, and default the value where a missing body is legitimate (const body = req.body ?? {}). In our own test upgrades, this change turned several tests red on one project until the default was added.
Related: express.urlencoded() now defaults extended to false. If your forms post nested fields, pass { extended: true } to keep the old parsing.
3. Route path syntax (path-to-regexp 8)
This applies to app.all(), app.use(), app.METHOD() and the same methods on a router.
| Express 4 pattern | Express 5 |
|---|---|
app.get('/*', ...) (bare wildcard) | app.get('/*splat', ...). This does not match / itself; use /{*splat} to match the root too. |
app.get('/:file.:ext?', ...) (optional with ?) | app.get('/:file{.:ext}', ...) (braces mark the optional part) |
app.get('/[discussion|page]/:slug', ...) (regex characters) | app.get(['/discussion/:slug', '/page/:slug'], ...) |
The characters ()[]?+! are reserved and must be escaped with \. Parameter names must be valid JavaScript identifiers or quoted.
What to search for: catch-all 404 routes written as app.all('*', ...), CORS preflight routes written as app.options('*', ...), and any path containing *, ?, ( or [. In our own test upgrades, app.options('*') needed rewriting.
The shape of req.params also changed. A wildcard now yields an array (for /*splat on /foo/bar, splat is ['foo', 'bar']), unmatched optional parameters are left out instead of being set to undefined, and for string paths req.params is a null-prototype object, so do not call object methods such as req.params.hasOwnProperty(...) on it.
4. Removed methods and call forms
These throw at runtime if called, so a search finds them all. Each has a direct replacement.
| Removed in Express 5 | Use instead |
|---|---|
app.del(path, fn) | app.delete(path, fn) |
req.param(name) | req.params.name, req.body or req.query, whichever you meant |
res.send(200) (status as a number) | res.sendStatus(200); to send a number as the body, send it as a string |
res.send(body, status), res.json(obj, status), res.jsonp(obj, status) | res.status(status).send(body) and the same chaining for json and jsonp |
res.redirect(url, status) | res.redirect(status, url) |
res.redirect('back'), res.location('back') | res.redirect(req.get('Referrer') || '/') |
res.sendfile() | res.sendFile() |
req.acceptsCharset(), req.acceptsEncoding(), req.acceptsLanguage() | the plural forms: req.acceptsCharsets(), req.acceptsEncodings(), req.acceptsLanguages() |
app.param(fn) and router.param(fn) (single argument) | app.param(name, fn) |
hidden and from options of res.sendFile() and express.static() | dotfiles and root |
express.static.mime | the mime-types package |
Smaller behaviour changes worth a search: res.status() now throws for anything but an integer from 100 to 999; res.vary() throws when called without a field; res.clearCookie() ignores maxAge and expires; req.host keeps the port number; and router.param() throws if given an array.
5. Static files: dotfiles and MIME types
express.static() now defaults dotfiles to "ignore", so dot-directories such as .well-known return 404. The migration guide names Android App Links, Apple Universal Links and ACME (Let's Encrypt) challenges as things this can break. Opt in for that directory:
app.use('/.well-known', express.static('public/.well-known', { dotfiles: 'allow' }));
app.use(express.static('public'));
Separately, .js files from express.static() and res.sendFile() are now served as text/javascript rather than application/javascript. Check any test or proxy rule that matches on the old value.
6. Async handlers and error handling
This one is an improvement, but it changes control flow. In Express 5, a rejected promise or a thrown error in a handler or middleware is passed to your error-handling middleware as if you had called next(err):
// Express 4 style
app.get('/user/:id', (req, res, next) => {
getUserById(req.params.id)
.then((user) => res.send(user))
.catch(next);
});
// Express 5
app.get('/user/:id', async (req, res) => {
const user = await getUserById(req.params.id);
res.send(user);
});
Existing .catch(next) code keeps working; you can remove it where it is noise. What to check: you have an error-handling middleware that sends a sensible response, and no handler relied on a rejection being swallowed.
7. Other changes in the guide
app.listen()passes errors such asEADDRINUSEto its callback instead of throwing them.- Debug namespaces for routing moved: use
DEBUG=express:*,router,router:*to see whatexpress:*used to show. res.render()now always behaves asynchronously.
A test plan that catches most of it
- Start from a green baseline on Express 4 and write down the test count. If tests are red or sparse today, fix that first; an upgrade cannot be judged against a suite that does not pass.
- Move Node to 18 or higher, then bump
expressto 5 alone. Run the suite, and run the app and hit each route group by hand or with a smoke script. Mock-based tests can miss thereq.queryandreq.paramschanges. - Search the code for each item above: assignments to
req.query,req.bodyreads,*and?in route strings, and each removed method. - Do not edit assertions to make tests pass. If a test needs changing because an API name changed, make the change deliberately and note it.
- Express publishes codemods for many of the mechanical changes (
npx codemod@latest @expressjs/v5-migration-recipe). They run third-party code against your repository, so use a branch and read the diff.
Start with the $79 baseline check: we run your tests as they are today and report passes, failures and skips, with no code changed. If your project has at least 30 meaningful tests and CI that is green today, the fixed-price Node bundle upgrade is $599: the Node runtime to Node 24 or 26 (both LTS; we target 24 by default, or 26 on request once tested on your project) plus Express 4 to 5, Jest and ESLint majors, for one project, delivered as a pull request or patch. The baseline fee is credited to an upgrade ordered within 30 days. The delivery check is that your own tests pass at least as well as before, with none deleted, skipped or weakened, and every package we held back is listed with the reason. If we cannot deliver a result that meets it, you pay nothing beyond the baseline fee. Green tests cover only what your tests cover, and we tell you where they do not reach.
Sources
- Express: Migrating to Express 5 (every Express claim above, including Node 18 as the minimum)
- Express 5.x API reference: application settings (the
query parsersetting)
Written 2026-11-18 against the Express 5 migration guide as published that day. Check the official guide for later changes.