# Upgrade an Express 4 App to Express 5 in Node.js

Yes. An agent upgrades Express 4 to 5, checks every route against the breaking changes, moves CI and Docker to a supported Node, and proves the app runs.

[Run this on Rush](https://cloud.getrush.ai/run/upgrade-express-5/nodejs/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent starts with an inventory, because an Express 5 upgrade is less about the version bump than about which removed or changed calls the app uses. In an app like OWASP/NodeGoat, `package.json` declares `express` at `^4.13.4` and `package-lock.json` resolves it to 4.16.4, with `body-parser` 1.18.3, `express-session` 1.15.6, `csurf` 1.9.0 and `helmet` 2.3.0 beside it. The agent reads `server.js` and every file under `app/routes/` and greps for the patterns the migration guide names: `app.del`, `req.param(`, `res.send(<number>)`, `res.json(obj, status)`, `res.redirect('back')`, `res.sendfile`, regular-expression characters in route paths and unnamed wildcards. Here it finds none: the routes in `app/routes/index.js` are plain paths plus one `:userId` parameter, `tutorial.js` mounts an `express.Router()` at `/tutorial` with a loop of static pages, and `error.js` is a four-argument handler calling `res.status(500)` and `res.render`. It writes that result into the pull request as a table, pattern by pattern, so a reviewer sees what was checked rather than only what changed.

The changes that do apply are around the framework rather than inside the routes. Express 5 requires Node 18 or newer, and this app's `Dockerfile` builds from `node:12-alpine`, its `.github/workflows/e2e-test.yml` tests a matrix of Node 10, 12 and 14, and `.travis.yml` lists old versions too; the agent moves the Dockerfile to a current LTS image and the workflow matrix to 18, 20 and 22, and notes `.travis.yml` as unused. `server.js` uses `bodyParser.json()` and `bodyParser.urlencoded({ extended: false })`; the agent switches both to `express.json()` and `express.urlencoded({ extended: false })`, which Express 5 provides, and drops `body-parser` from `package.json`. The `extended: false` the app already passes matches the new default, so form parsing behaves the same. `express.static` serves `app/assets` and keeps working, and the agent checks the assets directory for dotfiles because Express 5 ignores them by default.

Two behaviour changes get explicit attention because they do not show up as errors. `res.render` is asynchronous for every view engine in Express 5, and the app renders Swig templates through `consolidate`, so the agent reads how `error.js` and the route handlers call it and confirms nothing writes to the response after `render` returns. Rejected promises in handlers now reach the error handler automatically; the app's handlers are callback-based, so this changes nothing today, and the agent says so. It also runs the official Express 5 codemods, published under the `@expressjs` scope and run with `npx codemod@latest`, and reports that they produce no diff on this codebase, which agrees with the manual inventory.

The proof is the app running on the new version. The agent installs with `npm install express@5`, starts a MongoDB in its sandbox with `mongodb-memory-server`, seeds it with `node artifacts/db-reset.js` as `docker-compose.yml` does, starts the server with `npm start` on Node 22, and drives it in its browser: signup, login, `/dashboard`, `/profile` update, `/contributions`, `/memos`, the `/tutorial` pages and `/logout`, plus a deliberate bad URL to exercise `error.js`. The repository's end-to-end suite is Cypress 3.3.1, which predates Node 18; the agent tries `npm run test:ci` once and, if that Cypress cannot start, reports the browser session as the evidence and the Cypress upgrade as the next pull request rather than bundling it in.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Upgrade this Express 4 application to Express 5. Read package.json, package-lock.json, server.js, every file under app/routes, the Dockerfile and the CI workflows first. Grep the code for every removed or changed API the Express 5 migration guide names and report each pattern as found or not found. Replace body-parser with express.json and express.urlencoded, keeping the current extended setting, run the official v5 codemods, and move the Dockerfile base image and CI Node matrix to versions Express 5 supports. Start MongoDB and the app in the sandbox on a supported Node, drive signup, login, every protected page, the tutorial pages, logout and an error page in the browser, and try the existing test suite. Open a pull request with the inventory table and what was verified.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch that bumps `express` to 5 in `package.json` and `package-lock.json`, removes `body-parser`, edits the two middleware lines in `server.js`, changes the base image in `Dockerfile` and the Node matrix in `.github/workflows/e2e-test.yml`. The route files are unchanged, and the description explains that this is the outcome of checking them, not of skipping them.

The description holds the inventory table, one row per migration-guide pattern with found or not found and the file searched, the codemod's output, the browser walk-through with screenshots from the transcript at `GET /o/{org}/sessions/{id}/messages`, and the result of trying the Cypress suite on the new Node. It ends with the follow-ups it chose not to bundle: the Cypress version and the commented-out `helmet` and `csurf` blocks.

Before merging, a reviewer confirms the Node image tag matches what production runs, reads the two `express.json` and `express.urlencoded` lines, and decides whether to merge before or after the test-suite upgrade. A run that cannot start the app on Express 5 ends `needs_review` with the error quoted rather than a pull request claiming success.

## Run it on every Monday morning

The weekly upgrade automation, a `schedule` trigger with `cron` set to Monday morning in your `timezone`, bumps dependencies to their latest minor versions and runs the tests. When `npm outdated` shows a major version waiting, as Express 5 does for an Express 4 app, that run leaves it out and names it in its pull request, which is the signal to start this body as its own run with the repository in `resources`: a major upgrade deserves its own inventory and its own pull request.

The automation's runs count against its own `max_runs_per_hour` cap and a key's runs against its `max_concurrent` limit, so the weekly job and this one-off do not compete. When the turn ends, `GET /o/{org}/sessions/{id}` names the pull request, and a follow-up through `POST /o/{org}/sessions/{id}/messages`, for example to take on the Cypress upgrade next, wakes the parked sandbox with the app and its database still installed.

## Why run it on Rush?

An Express major is a long list of small removals, and the risk is in the ones you did not grep for: a `res.redirect('back')` in a rarely used handler, a regular expression in a route path, a `render` callback that assumed synchronous behaviour. The agent checks every pattern the guide names and records the result whether or not it found anything, so the review is of a checklist rather than a guess, and it fixes the Node version in Docker and CI that would otherwise fail the first deploy.

On Rush the app, a real MongoDB and the browser run in the agent's own sandbox on the Node version the upgrade needs, so nobody has to install Node 22 locally to find out whether the app starts. The browser walk-through and the inventory stay in the transcript, and the same body on your other Express 4 services runs the same inventory on each, in parallel, each with its own pull request.

## Frequently asked questions

### What if the app does use a removed API?

Then the inventory table says where, and the pull request fixes each one with the replacement the guide gives: `res.status(n).json(obj)` for `res.json(obj, n)`, `res.sendStatus(n)` for `res.send(n)`, `res.redirect(req.get('Referrer') || '/')` for `redirect('back')`, named wildcards like `/*splat` for `*`, and braces for optional segments. Each fix is a separate commit so the diff reads pattern by pattern.

### Why remove body-parser?

Because Express 5 ships `express.json()` and `express.urlencoded()` with the same options, so the extra package is one more dependency to update. The app's `extended: false` is carried over unchanged; it also happens to be the new default. If other code imports `body-parser` directly, the agent leaves the package in place and says so.

### Does the test suite still run?

The agent tries it. On this app the end-to-end suite is Cypress 3.3.1, which predates the Node versions Express 5 requires, so it may not start on Node 18 or later. In that case the description reports the attempt, uses the browser walk-through as the evidence for the upgrade, and lists the Cypress upgrade as a separate pull request rather than mixing two large changes.

### Will the Docker image change affect anything else?

Only the Node version inside the image. The agent moves the two `FROM node:12-alpine` stages to a current LTS Alpine tag and leaves the two-stage layout, the non-root `USER` and the `EXPOSE 4000` as they are. `docker-compose.yml`, which builds from this Dockerfile, needs no edit.

## More Node.js jobs

- [Upgrade a Node.js App to Node 24](https://getrush.ai/run/upgrade-node-version/nodejs/)
- [Write Unit Tests for a Node.js App](https://getrush.ai/run/write-unit-tests/nodejs/)
- [Add Account Lockout After Failed Logins to a Node.js App](https://getrush.ai/run/add-account-lockout/nodejs/)

## More jobs like this: Upgrade dependencies weekly

- [Upgrade firebase-functions and firebase-admin](https://getrush.ai/run/upgrade-firebase-functions/firebase-functions/)
- [Upgrade Laravel 11 to Laravel 13](https://getrush.ai/run/upgrade-framework-major/laravel/)
- [Upgrade Next.js 13 to Next.js 16](https://getrush.ai/run/upgrade-framework-major/nextjs/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
