Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ apps/site/pages/en/learn/getting-started/security-best-practices.md @nodejs/secu
apps/site/pages/en/learn/manipulating-files @nodejs/fs
apps/site/pages/en/learn/test-runner @nodejs/test_runner
apps/site/pages/en/learn/typescript @nodejs/typescript
apps/site/pages/en/learn/getting-started/userland-migrations.md @nodejs/userland-migrations
apps/site/pages/en/blog/migrations @nodejs/userland-migrations
171 changes: 98 additions & 73 deletions apps/site/pages/en/blog/migrations/v22-to-v24.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,86 +69,132 @@ Node.js' `configure` script will warn if you attempt to build Node.js with a com

Some breaking changes or End of Life (EOL) deprecations in Node.js 23 and 24 have associated codemods to help you update your codebase. Below is a list of the available codemods for this migration:

### `fs-access-mode-constants`

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.
### `crypto-rsa-pss-update`

This codemod handles [DEP0176](https://nodejs.org/api/deprecations.html#DEP0176).
In [DEP0154](https://nodejs.org/docs/latest/api/deprecations.html#DEP0154), the `generateKeyPair` and `generateKeyPairSync` methods in the `crypto` module deprecated the `hash`, `mgf1Hash`, and `saltLength` options for the `'rsa-pss'` key type in favor of `hashAlgorithm`, `mgf1HashAlgorithm`, and `saltLength` respectively.

The source code for this codemod can be found in the [fs-access-mode-constants directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/fs-access-mode-constants).
The source code for this codemod can be found in the [crypto-rsa-pss-update directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/crypto-rsa-pss-update).

You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/fs-access-mode-constants).
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/crypto-rsa-pss-update).

```bash
npx codemod run @nodejs/fs-access-mode-constants
npx codemod run @nodejs/crypto-rsa-pss-update
```

#### Example:
#### Example

```js displayName="Before"
const fs = require('node:fs');
const crypto = require('node:crypto');

fs.access('/path/to/file', fs.F_OK, callback);
fs.access('/path/to/file', fs.R_OK | fs.W_OK, callback);
crypto.generateKeyPair(
'rsa-pss',
{
modulusLength: 2048,
hash: 'sha256',
mgf1Hash: 'sha1',
saltLength: 32,
},
(err, publicKey, privateKey) => {
// callback
}
);
```

```js displayName="After"
const fs = require('node:fs');
const crypto = require('node:crypto');

fs.access('/path/to/file', fs.constants.F_OK, callback);
fs.access('/path/to/file', fs.constants.R_OK | fs.constants.W_OK, callback);
crypto.generateKeyPair(
'rsa-pss',
{
modulusLength: 2048,
hashAlgorithm: 'sha256',
mgf1HashAlgorithm: 'sha1',
saltLength: 32,
},
(err, publicKey, privateKey) => {
// callback
}
);
```

### `util-log-to-console-log`
### `dirent-path-to-parent-path`

This codemod transforms the usage of `dirent.path` to use `dirent.parentPath`.

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.
See [DEP0178](https://nodejs.org/api/deprecations.html#DEP0178).

So this codemod handle [DEP0059](https://nodejs.org/api/deprecations.html#DEP0059).
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/dirent-path-to-parent-path).

```bash
npx codemod run @nodejs/util-log-to-console-log
npx codemod run @nodejs/dirent-path-to-parent-path
```

#### Example:
#### Examples

##### readdir

```js displayName="Before"
const util = require('node:util');
const { readdir } = require('node:fs/promises');
const entries = await readdir('/some/path', { withFileTypes: true });
for (const dirent of entries) {
console.log(dirent.path);
}
```

```js displayName="After"
const { readdir } = require('node:fs/promises');
const entries = await readdir('/some/path', { withFileTypes: true });
for (const dirent of entries) {
console.log(dirent.parentPath);
}
```

##### opendir

util.log('Hello world');
```js displayName="Before"
import { opendir } from 'node:fs/promises';
const dir = await opendir('./');
for await (const dirent of dir) {
console.log(`Found ${dirent.name} in ${dirent.path}`);
}
```

```js displayName="After"
console.log(new Date().toLocaleString(), 'Hello world');
import { opendir } from 'node:fs/promises';
const dir = await opendir('./');
for await (const dirent of dir) {
console.log(`Found ${dirent.name} in ${dirent.parentPath}`);
}
```

### `zlib-bytesRead-to-bytesWritten`
### `fs-access-mode-constants`

The [`zlib.bytesRead`](https://nodejs.org/api/zlib.html#zlib_bytesread) property was deprecated ([DEP0108](https://nodejs.org/api/deprecations.html#DEP0108)) in favor of [`zlib.bytesWritten`](https://nodejs.org/api/zlib.html#zlib_byteswritten). This codemod replaces `zlib.bytesRead` with `zlib.bytesWritten` for consistent stream property naming. It handles both CommonJS and ESM imports.
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.

The source code for this codemod can be found in the [zlib-bytesRead-to-bytesWritten directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/zlib-bytesread-to-byteswritten).
This codemod handles [DEP0176](https://nodejs.org/api/deprecations.html#DEP0176).

You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/zlib-bytesread-to-byteswritten).
The source code for this codemod can be found in the [fs-access-mode-constants directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/fs-access-mode-constants).

You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/fs-access-mode-constants).

```bash
npx codemod run @nodejs/zlib-bytesread-to-byteswritten
npx codemod run @nodejs/fs-access-mode-constants
```

#### Example:
#### Example

```js displayName="Before"
const zlib = require('node:zlib');
const gzip = zlib.createGzip();
gzip.on('end', () => {
console.log('Bytes processed:', gzip.bytesRead);
});
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);
```

```js displayName="After"
const zlib = require('node:zlib');
const gzip = zlib.createGzip();
gzip.on('end', () => {
console.log('Bytes processed:', gzip.bytesWritten);
});
const fs = require('node:fs');

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

### `fs-truncate-to-ftruncate`
Expand All @@ -163,7 +209,7 @@ You can find this codemod in the [Codemod Registry](https://app.codemod.com/regi
npx codemod run @nodejs/fs-truncate-fd-deprecation
```

#### Example:
#### Example

```js displayName="Before"
const { truncate, open, close } = require('node:fs');
Expand All @@ -189,50 +235,29 @@ open('file.txt', 'w', (err, fd) => {
});
```

### `crypto-rsa-pss-update`
### `process-assert-to-node-assert`

In [DEP0154](https://nodejs.org/docs/latest/api/deprecations.html#DEP0154), the `generateKeyPair` and `generateKeyPairSync` methods in the `crypto` module deprecated the `hash`, `mgf1Hash`, and `saltLength` options for the `'rsa-pss'` key type in favor of `hashAlgorithm`, `mgf1HashAlgorithm`, and `saltLength` respectively.
This recipe transforms the usage of `process.assert` to use `node:assert` module.

The source code for this codemod can be found in the [crypto-rsa-pss-update directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/crypto-rsa-pss-update).
See [DEP0100](https://nodejs.org/api/deprecations.html#DEP0100).

You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/crypto-rsa-pss-update).
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/process-assert-to-node-assert).

```bash
npx codemod run @nodejs/crypto-rsa-pss-update
npx codemod run @nodejs/process-assert-to-node-assert
```

#### Example:
#### Example

```js displayName="Before"
const crypto = require('node:crypto');

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

```js displayName="After"
const crypto = require('node:crypto');

crypto.generateKeyPair(
'rsa-pss',
{
modulusLength: 2048,
hashAlgorithm: 'sha256',
mgf1HashAlgorithm: 'sha1',
saltLength: 32,
},
(err, publicKey, privateKey) => {
// callback
}
);
import assert from 'node:assert';
assert(condition, 'Assertion failed');
```

#### Additional Notes

This codemod use [`fs` capability](https://docs.codemod.com/jssg/security) to read the `package.json` file and determine if the project is using ES modules or CommonJS. Based on this information, it adds the appropriate import statement for the `assert` module.
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar error: 'use' should be 'uses' for correct subject-verb agreement.

Suggested change
This codemod use [`fs` capability](https://docs.codemod.com/jssg/security) to read the `package.json` file and determine if the project is using ES modules or CommonJS. Based on this information, it adds the appropriate import statement for the `assert` module.
This codemod uses [`fs` capability](https://docs.codemod.com/jssg/security) to read the `package.json` file and determine if the project is using ES modules or CommonJS. Based on this information, it adds the appropriate import statement for the `assert` module.

Copilot uses AI. Check for mistakes.
Loading