Guide · Runtimes

Node.js 20 is end of life: how to upgrade to Node 24 (or Bun)

Node.js 20 reached end of life on 30 April 2026. It still runs, but it no longer gets security fixes. The official migration guides only cover one version at a time, so I ran the same set of old Node 20 code on Node 20, 22, 24 and Bun to see exactly what breaks, and how to fix it before you switch.

The short answer

  • Go straight from 20 to 24. You don't need to deploy Node 22 in between, but it's a useful test step.
  • Most code runs unchanged. In my test, 8 old APIs broke on Node 24. Every fix also works on Node 20, so you can ship the fixes first and switch versions later.
  • Watch for the silent one: dirent.path doesn't throw on Node 24, it just becomes undefined.
  • Rebuild native addons and check old TLS certificates: Node 24 rejects 1024-bit RSA keys.
  • Bun is a real alternative for small services with mainstream dependencies, but not a shortcut: it has its own gaps, and on AWS Lambda managed Node.js is faster.

Why upgrade now

Node.js support end datesNode.js 20 support ended in April 2026. Node 22 is supported until April 2027, Node 24 until April 2028 and Node 26 until April 2029.Dec 2026Node 20Apr 2026Node 22Apr 2027Node 24Apr 2028Node 26Apr 2029
When each version stops getting security fixes. Node 20 is already past it; the dashed line is today.

The Node.js release schedule lists Node 20 as end of life since 30 April 2026. Your app won't stop working, but every month adds risk:

  • Security: new vulnerabilities in Node 20, its OpenSSL or its HTTP parser won't be fixed. Security audits and customer questionnaires ask about end-of-life runtimes.
  • Hosting: platforms retire old runtimes. On AWS Lambda, nodejs20.x has been deprecated since 30 April 2026, and you won't be able to create new functions on it from 29 July 2027 or update existing ones from 31 August 2027.
  • Libraries: new major versions of popular packages drop Node 20 from their engines, so you get stuck on old versions with their own unfixed bugs.

Node 24 or Node 26?

Since 28 October 2026, Node 26 is the active LTS, and Node 24 has moved to maintenance. Both get security fixes, so either is a valid target:

Node 24 “Krypton”Node 26 “Lithium”
Status todayMaintenance LTSActive LTS
Security fixes until30 April 202830 April 2029
Library supportOut since May 2025, widely testedOut since May 2026, newer
AWS Lambdanodejs24.xnodejs26.x

My rule: pick 26 if all your dependencies and platforms already support it, because you get a year more before the next upgrade. Otherwise go to 24. It's the smaller, better-tested step, and moving from 24 to 26 later is a much smaller job than this one. The tests and fixes below are for Node 24. Going to 26, apply them too, then also read the Node 26 release notes.

One more reason to plan ahead: from Node 27, Node.js moves to one major release a year, and every release becomes LTS.

What breaks: I tested it

I wrote a small script for each API that was removed or changed between Node 20 and 24, using it the way old code typically does, and ran every script on Node 20, 22, 24 and Bun:

Old codeNode 20Node 22Node 24Bun
JSON import with assert { type: "json" }WorksSyntaxErrorSyntaxErrorWorks
crypto.createCipher()WarnsRemovedRemovedMissing
util.isString() and other util.is*WorksWarnsRemovedWorks
process.assert()WarnsWarnsRemovedWorks
fs.truncate(fd, len) with a file descriptorWarnsWarnsThrowsWorks
tls.createSecurePair()WarnsWarnsRemovedMissing
TLS with a 1024-bit RSA certificateWorksWorks“ee key too small”Works
dirent.path from readdirWorksWorksundefined, no errorWorks
url.parse()WorksWorksWarnsWarns
util._extend()WorksWarnsWarnsWorks
require("punycode")WorksWarnsWarnsWorks
fs.R_OK, SlowBuffer, spawn(cmd, args, { shell: true })WorksWorksWarnsWorks

“Warns” means the code still runs but prints a deprecation warning, which is usually a sign the API will be removed in a later version. Two results stand out:

  • dirent.path is the dangerous one. Every other removal crashes loudly. This one returns undefined, so code that builds file paths from it quietly produces wrong paths, such as "undefined/report.pdf".
  • The 1024-bit certificate. Node 24 ships OpenSSL 3.5 with a stricter default security level. A server or client that loads an old certificate with a 1024-bit RSA key now fails with ee key too small. Look in internal services, test fixtures and connections to old partner systems.

What still works: require() of an ES module runs on all of them, including Node 20.19. new Buffer() still only warns, as it has for years. Bun, interestingly, accepts most of the old code that Node 24 rejects, which matters if you consider it as the alternative route below.

The upgrade path

Node 20 to Node 24 upgrade pathFour steps: find the old APIs, fix them while still on Node 20, test on Node 22 with deprecations as errors, then rebuild dependencies and deploy on Node 24.1. Auditcount old APIs2. Fix on Node 20ship as usual3. Test on Node 22--throw-deprecation4. Node 24rebuild · deploy
Steps 1 to 3 happen while production still runs Node 20, so the switch itself becomes a small change.

Step 1: measure the job

Count the files that use APIs that changed. Run this from the project root, with your source folder as the argument:

Shell · node24-audit.sh
#!/bin/bash
SRC=${1:-src}
for pattern in \
  'assert *\{ *type' \
  'createCipher\(|createDecipher\(' \
  'util\.(is[A-Z][a-zA-Z]*|_extend|log)\(' \
  'process\.assert\(' \
  'withFileTypes' \
  'fs\.truncate\(' \
  'createSecurePair' \
  'SlowBuffer' \
  'url\.parse\(' \
  'fs\.[FRWX]_OK' \
  'new Buffer\(' \
  'experimental-permission'
do
  printf '%-42s %s\n' "$pattern" \
    "$(grep -rElI --exclude-dir=node_modules "$pattern" "$SRC" | wc -l)"
done

echo "Native addons to rebuild:"
find node_modules -name '*.node' -not -path '*/test/*' \
  | sed 's|/build/.*||; s|/prebuilds/.*||' | sort -u

The number is how many files match each pattern. withFileTypes is there because it's how you get dirent objects. Check each match for .path by hand, since the plain word “path” is everywhere. The last part lists packages with compiled native code, such as better-sqlite3, bcrypt or sharp.

Also check your dependencies. A package that still calls punycode or url.parse() prints warnings on every start, and an old one may call removed APIs. npm outdated and the engines field of your main dependencies tell you what needs a bump.

Step 2: fix the breaking changes while still on Node 20

Every fix below runs on Node 20, 22 and 24 (I ran them on all three, and on Bun), so you can release them one by one before touching the runtime.

Import assertions become import attributes

JavaScript
// Node 20 only
import config from "./config.json" assert { type: "json" };

// Node 20, 22, 24
import config from "./config.json" with { type: "json" };

dirent.path becomes dirent.parentPath

JavaScript
const entries = await readdir(dir, { withFileTypes: true, recursive: true });

for (const entry of entries) {
  const full = path.join(entry.parentPath, entry.name);   // was: entry.path
}

Small replacements

OldNew
util.isArray(x), util.isString(x)Array.isArray(x), typeof x === "string"
util._extend(a, b)Object.assign(a, b) or { ...a, ...b }
process.assert(ok, msg)import assert from "node:assert", then assert(ok, msg)
fs.truncate(fd, len)fs.ftruncate(fd, len)
fs.R_OK, fs.W_OKfs.constants.R_OK, fs.constants.W_OK
url.parse(str)new URL(str, base)
new Buffer(n), SlowBuffer(n)Buffer.alloc(n), Buffer.allocUnsafeSlow(n)
tls.createSecurePair()new tls.TLSSocket(socket, options)
--experimental-permission--permission

crypto.createCipher: careful with stored data

createCipher() derived the key from a password in a weak way and used no random IV. The replacement is createCipheriv() with a real key derivation:

JavaScript · crypto.js
import { createCipheriv, createDecipheriv, randomBytes, scryptSync } from "node:crypto";

export function encrypt(text, secret) {
  const salt = randomBytes(16);
  const iv = randomBytes(12);
  const key = scryptSync(secret, salt, 32);
  const cipher = createCipheriv("aes-256-gcm", key, iv);
  const data = Buffer.concat([cipher.update(text, "utf8"), cipher.final()]);
  // store salt, IV and auth tag with the data
  return Buffer.concat([salt, iv, cipher.getAuthTag(), data]).toString("base64");
}

export function decrypt(payload, secret) {
  const buf = Buffer.from(payload, "base64");
  const key = scryptSync(secret, buf.subarray(0, 16), 32);
  const decipher = createDecipheriv("aes-256-gcm", key, buf.subarray(16, 28));
  decipher.setAuthTag(buf.subarray(28, 44));
  return Buffer.concat([decipher.update(buf.subarray(44)), decipher.final()]).toString("utf8");
}

The catch: the new code can't decrypt anything the old createCipher() encrypted. If you have stored data, such as tokens or encrypted fields in a database, decrypt and re-encrypt it while you're still on Node 20, where both functions exist. After the upgrade, the old function is gone.

Official codemods

The Node.js team publishes codemods for several of these changes. They're listed in the official 20 → 22 and 22 → 24 guides:

Shell
npx codemod run @nodejs/import-assertions-to-attributes
npx codemod run @nodejs/dirent-path-to-parent-path
npx codemod run @nodejs/process-assert-to-node-assert
npx codemod run @nodejs/fs-access-mode-constants
npx codemod run @nodejs/fs-truncate-fd-deprecation
npx codemod run @nodejs/tls-create-secure-pair-to-tls-socket

Run them on a clean branch and review the diff like any other change. There's also crypto-createcipheriv-migration, but it can't solve the stored-data problem above for you.

Step 3: test on Node 22 with deprecations as errors

Most APIs that Node 24 removes still exist in Node 22, with a deprecation warning. Run your test suite on Node 22 with warnings turned into errors, and they show up as failing tests while the code still works:

Shell
nvm install 22
NODE_OPTIONS=--throw-deprecation npm test

In my test, this caught process.assert, fs.truncate(fd), tls.createSecurePair and util.isString on Node 22. It did not catch dirent.path, which gives no warning in Node 22 and fails silently in 24. That's why step 1 searches for it.

Step 4: rebuild dependencies and switch

Native addons

Each Node.js major version has its own binary interface for compiled addons: 115 for Node 20, 127 for Node 22 and 137 for Node 24. An addon built for one version won't load in another. I loaded a better-sqlite3 build compiled for Node 22 in Node 24:

Node 24 output
Error: The module '.../better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 127. This version of Node.js requires
NODE_MODULE_VERSION 137. Please try re-compiling or re-installing

The fix is a clean install on the new version, not a copied node_modules folder. This matters most in Docker builds and CI caches:

Shell
rm -rf node_modules
npm ci

If an addon has no build for Node 24, upgrade the package. Old versions of better-sqlite3, bcrypt and sharp often don't support newer Node versions, and new versions often need a newer Node, which is one reason to do both together.

Change the version everywhere

The upgrade often fails because one place still pins Node 20. Check all of them:

WhereChange
.nvmrc / .node-version24
package.json"engines": { "node": ">=24" }
TypeScript typesnpm install -D @types/node@24
DockerfileFROM node:24-slim (or the Alpine image you use)
GitHub Actionsactions/setup-node with node-version-file: .nvmrc
AWS LambdaRuntime nodejs24.x. Callback-style handlers are no longer supported, so make handlers async
Other hosting (Vercel, Render, Heroku…)The Node version setting or engines field they read

Node 24 also comes with npm 11. If your CI runs npm ci, commit the lockfile that npm 11 produces so local and CI installs match.

What you get for free on Node 24

The upgrade also lets you delete some code and dependencies:

FeatureNode 20Node 24Replaces
Run .ts files directlyNoYests-node, tsx for scripts
fs.glob(), fs.globSync()NoYesglob, fast-glob
Global WebSocket clientNoYesws on the client side
Global URLPatternNoYespath-to-regexp for simple routing
node --run <script>NoYesFaster than npm run
node:sqliteNoYes, experimentalNative SQLite addons, eventually

Running TypeScript only removes the types. It doesn't check them, so keep tsc --noEmit in CI. Each removed package is one less thing to audit and update. More on that in reducing npm dependencies.

The alternative route: switch to Bun

If you have to touch the runtime anyway, it's fair to ask whether to move to Bun instead. Bun runs most Node.js code, installs packages much faster and has a test runner and bundler built in. I compare the two in detail in Bun vs Node.js in production. Here's what matters for a Node 20 app.

What my test showed

  • Bun ran most of the old code that Node 24 rejects. Import assertions, util.isString, process.assert, dirent.path and the 1024-bit certificate all worked on Bun 1.4.
  • Two old APIs are missing in Bun too: crypto.createCipher and tls.createSecurePair. Fix those whichever route you take.
  • Native addons are the real risk. Bun refused better-sqlite3 outright, with a message pointing to its own bun:sqlite.
  • Bun reports itself as Node.js: process.version returns v26.3.0, so engines checks and libraries that look at the version treat it as Node 26.

Being lenient isn't the same as being safe. Bun accepting a 1024-bit key doesn't make that key secure, so fix the same things as for Node 24.

How to try it

Shell
curl -fsSL https://bun.com/install | bash

bun install      # reads package-lock.json and writes bun.lock
bun run start    # your existing package.json scripts
bun test         # or keep your current runner: bun run test

bun install converts an existing package-lock.json, yarn.lock or pnpm-lock.yaml to bun.lock and keeps the versions you had resolved. The old lockfile stays untouched, so going back is easy.

If you used better-sqlite3, the built-in replacement has a very similar API:

JavaScript · db.js
import { Database } from "bun:sqlite";   // was: import Database from "better-sqlite3"

const db = new Database("app.db");
db.run("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, email TEXT)");
db.prepare("INSERT INTO users (email) VALUES (?)").run("a@example.com");

When Bun is the better route

  • Good fit: a small or new service with mainstream dependencies, where install, test and start-up speed matter, and you run it in a container or on a VPS.
  • Poor fit: a large, business-critical app with several native addons or an APM agent that only supports Node.js. Upgrade Node first. You can still try Bun for tooling later.
  • Not on AWS Lambda: Bun runs there only as a custom runtime, and cold-starts about 3.5× slower than managed Node.js in published tests.
  • Check memory over time, not only speed. Here's how I profile Bun memory.

Which route should you take?

Your situationRoute
Large or business-critical app, native addons, APM agentNode 24, or 26 if your dependencies support it
AWS Lambda functionsManaged nodejs24.x or nodejs26.x
Small service, mainstream dependencies, runs in a containerBun is worth a test
Not sureNode 24 now, then try Bun for tooling (bun install, bun test)

Whichever you choose, do steps 1 and 2 first. They make the switch itself small, and they make it easier to change your mind later.

How I tested

I wrote 25 small scripts. Each one uses one API that changed between Node 20 and 24, or one feature that was added. I ran them on Node 20.19.4, 22.14.0 and 24.16.0 and on Bun 1.4.4, on an M1 MacBook Air with macOS, and recorded whether each one worked, printed a deprecation warning or failed. The 1024-bit test starts a real TLS server and client with a self-signed certificate. The native addon test loaded an existing better-sqlite3 build compiled for Node 22. I ran the fixed code from step 2 on all four runtimes, with --throw-deprecation on, and it passed everywhere.

Limits: I didn't run the official codemods, and I didn't test Node 26. Node 22.14 is not the latest Node 22, and newer 22.x releases can run TypeScript files too.

FAQ

When did Node.js 20 reach end of life?

On 30 April 2026. Node.js 20 no longer gets security fixes or bug fixes. Node 22 is supported until 30 April 2027, Node 24 until 30 April 2028 and Node 26 until 30 April 2029.

Can I upgrade from Node 20 straight to Node 24?

Yes, there is no need to deploy Node 22 in between. Do use Node 22 as a test step: run your tests on it with --throw-deprecation, which turns most APIs that Node 24 removes into errors while they still exist.

Should I upgrade to Node 24 or Node 26?

Node 26 has been the active LTS since October 2026 and is supported a year longer, until April 2029. Node 24 is in maintenance until April 2028 and has had more time for libraries to catch up. Pick 26 if all your dependencies and platforms support it, otherwise 24.

What breaks when upgrading from Node 20 to Node 24?

In my tests: import assertions (assert { type: "json" }), crypto.createCipher, util.isString and the other util.is* helpers, process.assert, fs.truncate with a file descriptor, tls.createSecurePair, TLS certificates with 1024-bit RSA keys, and native addons that weren't rebuilt. dirent.path doesn't throw, it silently becomes undefined.

Is it still safe to run Node.js 20?

Your app keeps running, but new vulnerabilities in Node 20 won't be fixed. Hosting platforms are retiring it too: on AWS Lambda, nodejs20.x has been deprecated since 30 April 2026.

Should I switch to Bun instead of upgrading Node.js?

Only if you have a reason beyond the upgrade, such as faster installs, tests and start-up for a small service with mainstream dependencies. Bun runs most Node code, but not everything: in my test it refused better-sqlite3 and has no crypto.createCipher. On AWS Lambda, stay on the managed Node.js runtime.