How to Use the Express 4 to 5 Migration Prompt to Upgrade Routes Without Breaking Your API
Upgrade an Express 4 app to Express 5 route by route: rewrite wildcard, optional, and regex routes for the new path syntax, replace removed methods like app.del, req.param, and res.json with a status argument, handle the read only req.query and the simple query parser, drop try and catch wrappers that async error handling makes redundant, check middleware, and test before release.

Express 5 is a careful upgrade rather than a rewrite, but a few changes catch almost every team. Wildcard routes stop matching because the path syntax changed. A middleware that reassigned req.query starts throwing. A handler still calls res.json with a status argument. The Express 4 to 5 Migration Planner for Node.js APIs: path-to-regexp 8 Route Syntax for Named Wildcards and Optional Braces, Removed Methods, req.query Getter and Simple Parser, Async Error Handling, Middleware Compatibility, and a Test Plan prompt reads your actual routes, handlers, and middleware, then gives you a line by line migration plan with code diffs and a test plan.
What the prompt produces
- A readiness check, starting with the Node.js version Express 5 requires and the support status of each dependency.
- A route syntax table that rewrites every route for the new path matching rules: named wildcards, optional parts in braces, and inline regex moved into validation.
- A removed and changed API list with before and after code for methods such as app.del, req.param, res.json with two arguments, res.send with a number, res.sendfile, and res.redirect('back').
- Query and body changes, including the read only req.query getter, the new default query parser, and urlencoded defaults.
- Async error handling notes showing which wrappers or helper packages you can remove.
- Other behavior changes to check, such as status code validation and static file dotfiles.
- A migration order so you change one layer at a time.
- A test plan with one request per changed route.
How to fill the inputs
Stack lists your current Express and Node.js versions and the dependencies that touch Express. Include the production runtime, not just your laptop.
Routes should be the real route lines from your app and routers. The prompt only rewrites what you paste.
HandlerCode includes the parts of handlers that use request and response helpers. Search your codebase for req.param, res.json(, res.send(, res.redirect, and res.sendfile before you paste.
Middleware is the ordered list, including any custom middleware that modifies req.query or req.body.
Tests explains your test framework and deployment, so the test plan fits your tools.
Reading the example output
The example is an Express 4.19 API still running Node.js 16 in production:
- The first item is a blocker: Node.js 16 must be upgraded before Express 5.
- The route table rewrites four routes, including a wildcard that becomes a named splat parameter delivered as an array.
- An inline regex route loses its pattern and gets a router.param check instead.
- Each handler change is a small diff, such as moving the status into res.status(201).json(order).
- The sanitize middleware is flagged because it reassigns req.query, which Express 5 does not allow.
- The nested filter endpoint keeps working by opting back into the extended query parser.
- The test list covers root and nested paths, optional ids, invalid ids, nested query strings, and an async error.
Tips for better results
- Upgrade Node.js first and get your tests passing on Express 4 before changing Express.
- Search for wildcard and optional routes across every router file, including ones mounted from packages you own.
- Check the official Express migration guide and any codemods it provides before hand editing.
- Deploy behind a feature flag or to a canary instance if your API has many clients.
Mistakes to avoid
- Do not assume a wildcard parameter is still a string. It now arrives as an array of segments.
- Do not leave old async error helper packages in place without testing; they may no longer be needed.
- Do not rewrite routes the prompt cannot see. Paste them all, or note which files are missing.
- Do not ship without tests for invalid ids, since the old regex guard is now your own validation.
Who it is for
Node.js backend developers maintaining Express APIs, teams planning a runtime and framework upgrade together, and reviewers who want a clear checklist for an Express 5 pull request.
Related PromptDig links
Open the Express 4 to 5 Migration Planner for Node.js APIs: path-to-regexp 8 Route Syntax for Named Wildcards and Optional Braces, Removed Methods, req.query Getter and Simple Parser, Async Error Handling, Middleware Compatibility, and a Test Plan prompt and paste your routes and handlers to plan the upgrade. For more coding prompts, Browse more prompts. If you have a migration prompt that saved you time, Share a prompt.