Node.js v22 to v24

AugustinMauroy

Node.js v22 to v24

!

This article cover a part of the migration from Node.js v22 to v24. The userland migrations team is working on more codemods to help you with the migration.

This page provides a list of codemods to help you migrate your code from Node.js v22 to v24.

fs-access-mode-constants

In Node.js 24, the fs module introduced a runtime deprecation for F_OK, R_OK, W_OK, and X_OK getters exposed directly on node:fs. Get them from fs.constants or fs.promises.constants instead.

So this codemod handle DEP0176.

const fs = require('node:fs');

fs.access('/path/to/file', fs.F_OK, callback);
fs.access('/path/to/file', fs.R_OK | fs.W_OK, callback);

util-log-to-console-log

In Node.js v23, the util.log function was deprecated in favor of using console.log directly. Because it's an unmaintained legacy API that was exposed to user land by accident

So this codemod handle DEP0059.

Example:

const util = require('node:util');

util.log('Hello world');

zlib-bytesRead-to-bytesWritten

The zlib.bytesRead property was deprecated (DEP0108) in favor of zlib.bytesWritten. This codemod replaces zlib.bytesRead with zlib.bytesWritten for consistent stream property naming. It handles both CommonJS and ESM imports.

npx codemod run @nodejs/zlib-bytesRead-to-bytesWritten

Example:

const zlib = require('node:zlib');
const gzip = zlib.createGzip();
gzip.on('end', () => {
  console.log('Bytes processed:', gzip.bytesRead);
});

fs-truncate-to-ftruncate

The fs.truncate function was deprecated (DEP0081) when used with a file descriptor. Use fs.ftruncate instead.

npx codemod run @nodejs/fs-truncate-to-ftruncate

Example:

const { truncate, open, close } = require('node:fs');

open('file.txt', 'w', (err, fd) => {
  if (err) throw err;
  truncate(fd, 10, err => {
    if (err) throw err;
    close(fd, () => {});
  });
});

crypto-rsa-pss-update

Codemod to handle Node.js crypto deprecation DEP0154 by transforming deprecated RSA-PSS key generation options.

npx codemod run @nodejs/crypto-rsa-pss-update

Example:

const crypto = require('node:crypto');

crypto.generateKeyPair(
  'rsa-pss',
  {
    modulusLength: 2048,
    hash: 'sha256',
    mgf1Hash: 'sha1',
    saltLength: 32,
  },
  (err, publicKey, privateKey) => {
    // callback
  }
);

Source Code

The source code for this codemod can be found in the crypto-rsa-pss-update directory.

You can find this codemod in the Codemod Registry.