Full answer
Preparation
- Read the release announcement and the changelog for each major between your version and the target (the breaking changes section). Check the deprecation list (DEPxxxx codes).
- Check your dependencies: do they support the new version? Native addons (bcrypt, sharp, argon2) need prebuilt binaries or a compiler for the new ABI. Update the lockfile and run npm audit.
- Check the platform: Docker base image, CI images, serverless runtimes, and operating system libraries (musl or glibc).
Find problems early
- Run the full test suite on the new version in CI, next to the old one (a matrix: 22 and 24).
- Run with --throw-deprecation in CI so deprecated API use fails the tests. Use --trace-deprecation (or NODE_OPTIONS) to print the stack that triggered a warning. A deprecation in Node can become a removal in the next major version.
- Watch for behavioural changes: default values (for example stream highWaterMark changes), stricter validation, changed error messages, and removed APIs.
- Test performance and memory with a realistic load. The V8 version changes with every major.
Roll out
- Update .nvmrc, the engines field, Dockerfile and CI together. engines with engine-strict makes npm enforce it.
- Deploy to staging, then a small share of production (canary), compare error rates, latency and memory, and keep the old image ready for rollback.
- Upgrade one LTS at a time, and schedule it regularly, so changes stay small.
Afterwards: remove workarounds for the old version, and use new built-in features carefully instead of adding dependencies.
javascript
const { spawnSync } = require('node:child_process');
const run = (flags, code) => {
const r = spawnSync(process.execPath, [...flags, '-e', code], { encoding: 'utf8' });
return { exit: r.status, stderr: r.stderr };
};
// 1. A deprecated API normally prints a warning and keeps working.
const plain = run([], "require('node:url').parse('http://example.com/a'); console.log('still works')");
console.log('1. default : exit', plain.exit, '| warning code:', (plain.stderr.match(/DEP\d+/) || ['none'])[0]);
// 2. In CI, turn the deprecation into an error.
const strict = run(['--throw-deprecation'], "require('node:url').parse('http://example.com/a'); console.log('still works')");
console.log('2. in CI : exit', strict.exit, '| error mentions:', (strict.stderr.match(/DEP\d+/) || ['none'])[0]);
// 3. Find where the warning comes from.
const traced = run(['--trace-deprecation'], "function oldWay() { require('node:url').parse('http://example.com'); } oldWay();");
console.log('3. with trace : stack names the calling function:', /oldWay/.test(traced.stderr));
// 4. A tiny engines check, like the one npm does with engine-strict.
const engines = { node: '>=22' };
const major = (v) => Number(String(v).replace(/^[^\d]*/, '').split('.')[0]);
const ok = major(process.versions.node) >= major(engines.node);
console.log('4. engines check:', engines.node, 'is satisfied by', process.version + ':', ok);
console.log(' a project that needs >=26 on this version:', major(process.versions.node) >= 26);Child processes run the same deprecated call with different flags. It also shows a simplified engines check. Real checks use the semver package or npm itself. Save it as app.js and run it with node app.js. Output (Node.js v24.22.1, run once): 1. default : exit 0 | warning code: DEP0169 2. in CI : exit 1 | error mentions: DEP0169 3. with trace : stack names the calling function: true 4. engines check: >=22 is satisfied by v24.22.1: true a project that needs >=26 on this version: false
Key points
- Read the breaking changes for every major you cross.
- Test on the new version in a CI matrix.
- Use --throw-deprecation and --trace-deprecation to find deprecated API use.
- Native addons need new builds.
- Canary rollout with monitoring and a quick rollback.
Common mistakes
- Upgrading production first and testing later.
- Ignoring deprecation warnings until the API is removed.
- Forgetting native addons and the Docker base image.
- Skipping several major versions at once.
- Different Node versions in local, CI and production.
Follow-ups
- How do you list which dependencies break on a new Node version?
- What does engine-strict do?
- How would you do a canary deploy of a new runtime version?
Tips
- Describe prepare, find, roll out.
- Name --throw-deprecation.
- Say 'one LTS at a time'.