Development Playbook

Move a Node 22 service to Node 26 with a deprecation ledger as the agent's worklist

Node's own warnings are a better migration brief than a changelog summary. A 50-line script turns them into a worklist, and a three-version test gate proves the agent's fixes. About 15 minutes to try.

Stepped paper stairs rising through layered dark paper cut-outs to a bright open doorway.

A service has been on Node 22 since the day it was written. Node 22 is in maintenance and stops getting fixes on 30 April 2027, so the upgrade is on the calendar, and nobody wants to be the person who reads three major release posts looking for what applies to this codebase. The usual shortcut is to paste the release notes into an agent and ask it to “make this work on Node 26”. The agent produces a confident diff, the tests pass, and nobody can say what it did or didn’t look for.

Node already knows which of your calls are on borrowed time. Every deprecated API your code touches prints a DEP code with a stack trace, if you ask it to. Collect those into a ledger, hand the ledger to the agent as the worklist, and the brief is no longer a summary of other people’s release notes. It’s a list of file, line and code, produced by the runtime from your own tests.

This Playbook builds that ledger, runs an agent through it one DEP code at a time, and gates the result on the same suite passing on Node 22, 24 and 26. It works with any coding agent that can read files and run a shell, because the worklist is a plain text file and the check is a script. Allow about 15 minutes to try it on a real repo.

Which Node to run the ledger on

The obvious choice is the target, Node 26. It’s the wrong one. Removed APIs don’t warn, they vanish, so a ledger taken on Node 26 can’t list what 26 took away.

The Node release schedule puts Node 24 in maintenance since 20 October 2026 and Node 26 in LTS since 28 October 2026. Node 25 ended on 1 June 2026, which matters for one reason: some APIs were deprecated in 24, removed in 25, and so are simply gone on 26. The fs.R_OK family is the example below. Node 24 is the last LTS line that still warns about them.

So the rule is: take the ledger on Node 24, the newest line that warns about everything Node 26 removed, and use Node 26 as the finish line. Node 22 stays in the matrix as the baseline, because production is still on it while the migration is in flight.

Step 1: the ledger script

Save this as scripts/deprecation-ledger.mjs. It runs any command under a chosen Node binary with --trace-deprecation (print the stack for each warning) and --pending-deprecation (also warn for deprecations that are documentation-only so far, and for code in node_modules), then prints one entry per DEP code with the first call site that isn’t Node’s own code or a dependency.

// Usage: node scripts/deprecation-ledger.mjs <node-binary> -- <command...>
// Runs the command with the given node first on PATH and prints every
// distinct DEP code the run emitted, with the first call site that is not
// inside node_modules.
import { spawnSync } from "node:child_process";
import { dirname } from "node:path";

const [nodeBin, sep, ...cmd] = process.argv.slice(2);
if (!nodeBin || sep !== "--" || cmd.length === 0) {
  console.error("usage: deprecation-ledger.mjs <node-binary> -- <command...>");
  process.exit(2);
}

const env = {
  ...process.env,
  PATH: `${dirname(nodeBin)}:${process.env.PATH}`,
  NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ""} --trace-deprecation --pending-deprecation`.trim(),
};
const run = spawnSync(cmd[0], cmd.slice(1), { env, encoding: "utf8" });
const lines = `${run.stdout}\n${run.stderr}`.split("\n");

const ledger = new Map();
for (let i = 0; i < lines.length; i++) {
  const m = lines[i].match(/\[(DEP\d{4})\] DeprecationWarning: (.*)$/);
  if (!m) continue;
  const [, code, message] = m;
  let site = null;
  for (let j = i + 1; j < lines.length && /^\s+at /.test(lines[j]); j++) {
    if (!lines[j].includes("node_modules") && !lines[j].includes("(node:") && !lines[j].includes(" node:")) {
      site = lines[j].trim().replace(`${process.cwd()}/`, "");
      break;
    }
  }
  const entry = ledger.get(code) ?? { message, count: 0, site };
  entry.count++;
  entry.site ??= site;
  ledger.set(code, entry);
}

console.log(`tests exit code: ${run.status}`);
if (ledger.size === 0) console.log("no deprecation warnings");
for (const [code, e] of [...ledger].sort()) {
  console.log(`${code} x${e.count}  ${e.message.slice(0, 70)}`);
  console.log(`    first call site: ${e.site ?? "(only in node_modules or Node internals)"}`);
}
process.exit(ledger.size === 0 && run.status === 0 ? 0 : 1);

It exits 0 only when the tests pass and the ledger is empty, which turns it into a gate later. The PATH line is how it selects a Node version: whatever node the test command resolves is the one that runs. On a machine with a version manager, put the binary you want first on PATH (or use the manager’s own exec command) and pass its path as the first argument.

Step 2: take the ledger on Node 24

For a project whose tests run with Vitest, the command is:

node scripts/deprecation-ledger.mjs "$(which node)" -- npx vitest run

Run it with a Node 24 binary first on PATH. Against a small module with five legacy calls (a url.parse, a new Buffer, a util.isArray, a util._extend and an fs.R_OK), it prints:

tests exit code: 0
DEP0005 x1  Buffer() is deprecated due to security and usability issues. Please us
    first call site: at tag (src/legacy.ts:10:10)
DEP0044 x1  The `util.isArray` API is deprecated. Please use `Array.isArray()` ins
    first call site: at asList (src/legacy.ts:13:10)
DEP0060 x1  The `util._extend` API is deprecated. Please use Object.assign() inste
    first call site: at withDefaults (src/legacy.ts:16:10)
DEP0169 x1  `url.parse()` behavior is not standardized and prone to errors that ha
    first call site: at hostOf (src/legacy.ts:7:10)
DEP0176 x1  fs.R_OK is deprecated, use fs.constants.R_OK instead
    first call site: at canRead (src/legacy.ts:19:35)

Two things stand out. The tests pass (exit code: 0), so a green suite says nothing about any of this. And five distinct codes took one test run to find, each with a file and line. That’s the worklist.

Run the same command on Node 22 and DEP0176 is missing, because 22 doesn’t warn about the fs constants. Run it on Node 26 and DEP0176 is missing for a different reason, which is the next section.

The one that removal hides

Here is that fs.R_OK line, run on all three versions:

node -e "console.log(process.version, typeof require('fs').R_OK, require('fs').constants.R_OK)"
v22.23.5 number 4
(node:672) [DEP0176] DeprecationWarning: fs.R_OK is deprecated, use fs.constants.R_OK instead
v24.22.3 number 4
v26.13.1 undefined 4

(The warning prints to stderr and lands between the version lines, which is why the 24 line comes after it.) On Node 26 fs.R_OK is undefined. The Node docs record DEP0176 as a runtime deprecation in v24.0.0 and end-of-life in v25.0.0.

The code in the example was accessSync(path, fs.R_OK). With undefined as the mode, accessSync falls back to its default, which is an existence check. No exception, no warning, and the test that calls canRead("package.json") still passes on Node 26, because the file exists. What the function checks has quietly changed from “readable” to “exists”. On a real service that’s a permissions check that stopped checking permissions.

TypeScript catches the typed version of this: the @types/node declarations no longer include fs.R_OK or util._extend, so a plain fs.R_OK is a compile error. The example above reaches it through an any cast, which is how this sort of call survives in older code, in .js files and behind wrapper libraries. Two defences, both cheap: take the ledger on Node 24 so the warning exists to be found, and add a test per call site that asserts behaviour, not just “doesn’t throw”.

Step 3: pin the behaviour before the agent touches it

Not every replacement is a drop-in. The url.parse call in the example is parse(u).hostname, and the documented replacement is the WHATWG URL class. Before the fix, add the tests that describe what the code does today on awkward input:

import { expect, test } from "vitest";
import { hostOf } from "../src/legacy.js";

test("hostOf: relative path has no host", () => {
  expect(hostOf("/just/a/path")).toBeNull();
});

test("hostOf: absolute URL", () => {
  expect(hostOf("https://example.com:8080/a?b=1")).toBe("example.com");
});

Now do the mechanical replacement (new URL(u).hostname) and run the suite:

 × hostOf: relative path has no host
TypeError: Invalid URL
 Tests  1 failed | 5 passed (6)

url.parse returns an object with a null hostname for a relative path. new URL throws. An agent that swaps the call and sees the original five tests pass would ship the throw. The new test makes the agent choose, and the fix that preserves behaviour is:

export function hostOf(u: string): string | null {
  return URL.canParse(u) ? new URL(u).hostname : null;
}

Whether the old null is what you want is a product question. The point is that the migration doesn’t make it silently.

Step 4: hand the ledger to the agent

Save the ledger output to migration/deprecations.txt and give the agent a brief that is about process, not about Node. The wording works unchanged in any agent:

Read migration/deprecations.txt. It lists the deprecated Node APIs this
repo's tests call, with file and line.

For each DEP code, in order:
1. Find every call site in src/ (the ledger shows only the first one).
2. Before changing anything, write a Vitest test that pins the current
   behaviour for awkward input: null, undefined, empty, relative, invalid.
   Run it and confirm it passes on the old code.
3. Make the replacement the Node docs recommend for that DEP code.
4. Run the full suite. If a test fails, the replacement changed behaviour:
   make the new code match the old behaviour, don't edit the test.
5. Commit with the DEP code in the message.

Do not touch anything that isn't in the ledger. Do not use `any`,
`as unknown as`, or @ts-ignore. When the list is done, run
`node scripts/deprecation-ledger.mjs "$(which node)" -- npx vitest run`
and paste the output.

Step 2 is the one an agent skips unless it’s told, and it’s the step that catches the URL difference. One commit per DEP code means a reviewer can read each as a unit and revert one without the rest. The “don’t edit the test” line matters for the same reason it does in any upgrade where the suite is the judge : a failing test is the only evidence the agent has that it changed behaviour.

For the mechanical cases there’s a shortcut the Node docs themselves point to. DEP0044, DEP0060 and DEP0176 each list a codemod (npx codemod@latest @nodejs/util-is, @nodejs/util-extend-to-object-assign and @nodejs/fs-access-mode-constants). Those weren’t run for this piece, so treat them as documented, and read the diff they produce before committing it. They’re a good first move because a codemod’s changes are uniform and easy to review, which leaves the agent for the judgement calls such as url.parse.

Step 5: the three-version gate

When the ledger is empty on Node 24, prove the result on all three lines. Locally that’s the ledger script run three times with a different binary first on PATH. In CI, a matrix:

name: node-matrix
on: [pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node: [22, 24, 26]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
          cache: npm
      - run: npm ci
      - run: node scripts/deprecation-ledger.mjs "$(which node)" -- npx vitest run

That workflow is standard setup-node usage and wasn’t run here. Pin the action versions to whatever your organisation already uses. Run locally against the example project, the same command prints this on each of 22, 24 and 26 after the fixes:

tests exit code: 0
no deprecation warnings

Because the ledger script exits non-zero on any warning, a new url.parse landing in a later pull request fails the Node 22 job today, not in April 2027. That’s the real payoff of the exercise: the migration stops being an event.

What else is in Node 26 that no ledger will show

A deprecation ledger sees only APIs your tests execute and Node warns about. The Node 26.0.0 release post (5 May 2026) lists changes that never produce a warning, and a few are worth a manual look:

  • Temporal is enabled by default. If your code or a dependency feature-detects globalThis.Temporal and picks a polyfill or a different path when it exists, behaviour changes without an error.
  • NODE_MODULE_VERSION is now 147, so native addons built for Node 22 or 24 need a rebuild or a prebuilt binary for 26.
  • Undici, which backs fetch, moved to 8.0.2.
  • http.Server.prototype.writeHeader() and the _stream_* modules are removed. A search for those names is faster than waiting for a test to hit them.
  • module.register() is now a runtime deprecation. If a loader or an instrumentation package registers hooks that way, expect a warning from code you don’t own, and check for a newer release of that package.
  • --experimental-transform-types is gone. A project that ran TypeScript directly with that flag needs another route.

Give the agent that list as a second, shorter task: grep for each name, report hits, change nothing without a test. It’s a search job, not a runtime one.

Make it yours

Dependencies are the usual surprise. Because the script passes --pending-deprecation, warnings from code in node_modules show up too, and the call site column then reads (only in node_modules or Node internals). Those entries are not for the agent to edit. They become a list of packages to upgrade, and the agent’s task is to find the first version of each that no longer warns.

For a service that isn’t tested with Vitest, change the command after --. Anything that exits non-zero on failure works: npm test, a Playwright run, a script that starts the server and hits ten endpoints. The ledger only knows about code that ran, so a smoke script that exercises startup, a request and shutdown covers more than a unit suite does.

If a dependency is stuck on a deprecated API and you can’t upgrade yet, --disable-warning=DEP0xxx silences one code, and the Node CLI docs show the form node --disable-warning=DEP0025. Put the exception in the ledger script as an allow-list with a comment and an expiry date. An unexplained suppression is how a migration like this stalls.

What goes wrong

Coverage is the ceiling. A deprecated call on a code path no test reaches never prints a warning. Check the ledger against a grep for the obvious ones (url.parse, new Buffer(, util.isArray, _extend, fs.F_OK) and treat any grep hit that isn’t in the ledger as a coverage gap to fix with a test first.

The counts in the ledger are not call counts. Node prints some deprecations once per process, so treat the count as a rough signal and the call site as the useful column.

Application deprecations such as DEP0169 warn the first time the API is used in a process, so a call site that runs second in the same process is not listed. Fix the first, rerun the ledger, and the next one appears.

The agent will sometimes “fix” a warning by hiding it. Reject any diff that touches NODE_OPTIONS, adds --no-deprecation or edits the ledger script. The brief above says to touch only what’s listed, and the gate is the backstop.

Don’t bother with any of this for a small service with a good type-checked suite and no dependencies on old APIs: upgrade, run the tests on Node 26, done. The ledger earns its keep on codebases old enough to have new Buffer( in them.

First 15 minutes

Install Node 24 next to the version you use (a version manager, or a container). Copy the script, run it against your test command with Node 24 first on PATH, and read the output. If the ledger is empty, run the same command on Node 26 and you’re most of the way there. If it isn’t, paste the brief above into your agent with the ledger attached, and have it fix the first DEP code only. Review that one commit before letting it continue.