You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/site/pages/en/blog/migrations/v12-to-v14.mdx
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,12 @@ This page provides a list of codemods to help you migrate your code from Node.js
18
18
19
19
## `util-print-to-console-log`
20
20
21
-
This recipe transforms the usage of log functions from util, `print`, `puts`, `debug`, `error` to use `console.log()` or`console.error()`.
21
+
This recipe transforms calls of various now-deprecated `node:util` log functions into the modern alternative, `console.log` and`console.error`:
22
22
23
-
So this codemod handle [DEP0026](https://nodejs.org/api/deprecations.html#DEP0026), [DEP0027](https://nodejs.org/api/deprecations.html#DEP0027), [DEP0028](https://nodejs.org/api/deprecations.html#DEP0028) and [DEP0029](https://nodejs.org/api/deprecations.html#DEP0029).
Copy file name to clipboardExpand all lines: apps/site/pages/en/blog/migrations/v14-to-v16.mdx
+23-5Lines changed: 23 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,9 +17,7 @@ This page provides a list of codemods to help you migrate your code from Node.js
17
17
18
18
## `create-require-from-path`
19
19
20
-
In Node.js v16, the `createRequire` function was introduced to allow you to create a `require` function that can be used in ESM modules. This codemod will help you replace the old `createRequireFromPath` function with the new `createRequire` function.
21
-
22
-
So this codemod handle [DEP0130](https://nodejs.org/api/deprecations.html#DEP0130).
20
+
Node.js v16 replaced the [`createRequireFromPath`](https://nodejs.org/api/module.html#module_module_createrequirefrompath) function, deprecated in [DEP0148](https://nodejs.org/api/deprecations.html#DEP0148), with the modern [`createRequire`](https://nodejs.org/api/module.html#module_module_createrequire) function. This codemod replaces calls of the deprecated function with the modern alternative mentioned.
23
21
24
22
```bash
25
23
npx codemod run @nodejs/create-require-from-path
@@ -30,15 +28,13 @@ npx codemod run @nodejs/create-require-from-path
@@ -71,6 +67,28 @@ if (require.main === 'mod.js') {
71
67
}
72
68
```
73
69
70
+
## `process-mainModule-to-require-main`
71
+
72
+
The [`process.mainModule`](https://nodejs.org/api/process.html#process_process_mainmodule) property was deprecated ([DEP0144](https://nodejs.org/api/deprecations.html#DEP0144)) in favor of [`require.main`](https://nodejs.org/api/modules.html#modules_accessing_the_main_module). This codemod replaces calls of the deprecated property with the modern alternative mentioned.
73
+
74
+
```bash
75
+
npx codemod run @nodejs/process-mainModule-to-require-main
76
+
```
77
+
78
+
### Example:
79
+
80
+
```js displayName="Before"
81
+
if (process.mainModule) {
82
+
console.log('This script is the main module');
83
+
}
84
+
```
85
+
86
+
```js displayName="After"
87
+
if (require.main===module) {
88
+
console.log('This script is the main module');
89
+
}
90
+
```
91
+
74
92
## `rmdir`
75
93
76
94
The `fs.rmdir` function was deprecated in favor of `fs.rm` with the `{ recursive: true }` option. This codemod will help you replace the old `fs.rmdir` function with the new `fs.rm` function.
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.
60
+
61
+
```bash
62
+
npx codemod run @nodejs/zlib-bytesRead-to-bytesWritten
The [`fs.truncate`](https://nodejs.org/api/fs.html#fs_fs_truncate_path_len_callback) function was deprecated ([DEP0081](https://nodejs.org/api/deprecations.html#DEP0081)) when used with a file descriptor. Use [`fs.ftruncate`](https://nodejs.org/api/fs.html#fs_fs_ftruncate_fd_len_callback) instead.
86
+
87
+
```bash
88
+
npx codemod run @nodejs/fs-truncate-to-ftruncate
89
+
```
90
+
91
+
### Example:
92
+
93
+
```js displayName="Before"
94
+
const { truncate, open, close } =require('node:fs');
95
+
96
+
open('file.txt', 'w', (err, fd) => {
97
+
if (err) throw err;
98
+
truncate(fd, 10, err=> {
99
+
if (err) throw err;
100
+
close(fd, () => {});
101
+
});
102
+
});
103
+
```
104
+
105
+
```js displayName="After"
106
+
const { ftruncate, open, close } =require('node:fs');
107
+
108
+
open('file.txt', 'w', (err, fd) => {
109
+
if (err) throw err;
110
+
ftruncate(fd, 10, err=> {
111
+
if (err) throw err;
112
+
close(fd, () => {});
113
+
});
114
+
});
115
+
```
116
+
117
+
## `crypto-rsa-pss-update`
118
+
119
+
Codemod to handle Node.js crypto deprecation [DEP0154](https://nodejs.org/docs/latest/api/deprecations.html#DEP0154) by transforming deprecated RSA-PSS key generation options.
0 commit comments