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
34 changes: 25 additions & 9 deletions apps/site/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,6 @@
}
}
},
"migrations": {
"label": "components.navigation.learn.migrations.links.migrations",
"items": {
"introduction": {
"link": "/learn/migrations/introduction",
"label": "components.navigation.learn.migrations.links.introduction"
}
}
},
"modules": {
"label": "components.navigation.learn.modules.links.modules",
"items": {
Expand Down Expand Up @@ -411,6 +402,31 @@
"label": "components.navigation.learn.testRunner.links.collectingCodeCoverage"
}
}
},
"userland-migrations": {
"label": "components.navigation.learn.userland-migrations.links.userland-migrations",
"items": {
"introduction": {
"link": "/learn/userland-migrations/introduction",
"label": "components.navigation.learn.userland-migrations.links.introduction"
},
"ecosystem": {
"link": "/learn/userland-migrations/ecosystem",
"label": "components.navigation.learn.userland-migrations.links.ecosystem"
},
"v22-to-v24": {
"link": "/learn/userland-migrations/v22-to-v24",
"label": "components.navigation.learn.userland-migrations.links.v22-to-v24"
},
"v20-to-v22": {
"link": "/learn/userland-migrations/v20-to-v22",
"label": "components.navigation.learn.userland-migrations.links.v20-to-v22"
},
"v14-to-v16": {
"link": "/learn/userland-migrations/v14-to-v16",
"label": "components.navigation.learn.userland-migrations.links.v14-to-v16"
}
}
}
}
}
Expand Down
28 changes: 0 additions & 28 deletions apps/site/pages/en/learn/migrations/introduction.md

This file was deleted.

23 changes: 23 additions & 0 deletions apps/site/pages/en/learn/userland-migrations/ecosystem.md
Copy link
Member

Choose a reason for hiding this comment

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

What's the point of this file?

Copy link
Member Author

@AugustinMauroy AugustinMauroy Jul 30, 2025

Choose a reason for hiding this comment

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

Second part of your goal like. It's will host all codemod related to ecosystem not specific node version

  • jest-to-node-test (pr opened)
  • mocha-to-node-test (issue opened)
  • axios-to-fetch (in my brain)
  • correct-ts-specifiers (released)

Copy link
Member

Choose a reason for hiding this comment

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

Can we outsource this list, since it'll change often, i.e. in the main file, have a paragraph about "Ecosystem" upgrades, and "Migration" upgrades, with a link to the list of each in the Codemod repository? This'll also resolve my concern at #8053 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah it's solve that. But why I'm doing this pr is to use your cool UI to show our codemod

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: Ecosystem to Node.js
layout: learn
authors: AugustinMauroy
---

# Ecosystem to Node.js

Sometimes the ecosystem creates awesome tools or libraries for node.js, but a native alternative is present in Node.js. So, this page shows you codemod that handle this case.

## `correct-ts-specifiers`

When you want to [run typescript natively in Node.js](/learn/typescript/run-natively), you need to have a correct "specifiers" in your [imports statements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import).

To run this codemod, you have to use this command:

```bash
npx codemod run @nodejs/correct-ts-specifiers
```

## Feedback

If you have any tools that you would like to be handle by userland-migrations, please open an issue on the [Node.js Userland Migrations repository](https://github.com/nodejs/userland-migrations/issues).
52 changes: 52 additions & 0 deletions apps/site/pages/en/learn/userland-migrations/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: Userland Migrations
layout: learn
authors: JakobJingleheimer, AugustinMauroy
---

![Node.js Userland Migrations](https://raw.githubusercontent.com/nodejs/userland-migrations/main/.github/assets/Userland-Migration-Tagline.png)

# Userland Migrations

Node.js offers migrations for "userland" code (anything outside the node executable) to help adopt new features and handle breaking changes. These are built in collaboration with [Codemod](https://codemod.com), a platform focused on making it easy to build, share, and run codemods.

Official migrations are published under the `@nodejs` scope within the [Codemod registry](https://codemod.link/nodejs-official). These have been reviewed and/or authored by Node.js members.

## Goal

The Node.js Userland Migrations team seeks to help developers migrate their codebases to the latest Node.js versions, making it easier to handle deprecations, new features, and breaking changes.

## How to use a Codemod

To use a codemod, you can run the following command in your terminal:

```bash
npx codemod <codemod-name>
```

Replace `<codemod-name>` with the name of the codemod you want to run. For example, if you want to run the `@nodejs/import-assertions-to-attributes` codemod on your project, you would run:

```bash
npx codemod @nodejs/import-assertions-to-attributes
```

## Good Practices

- **Run migrations in a separate branch**: If you are using a version control system like Git, it is a good practice to run migrations in a separate branch. This allows you to review the changes before merging them into your main branch.
- **Review changes**: After running a migration, review the changes made to your codebase. Ensure that the migration has not introduced any unintended side effects or issues.
- **Test your code**: After running a migration, it is important to test your code to ensure that everything is working as expected. Run your test suite and check for any errors or failures
- **Format and or lint your code**: After running a migration, it is a good practice to format and lint your code. This ensures that your code follows the project's coding standards and is easier to read and maintain.

## Feedback

If you have any feedback or suggestions for improvements, please open an issue on the [Node.js Userland Migrations repository](https://github.com/nodejs/userland-migrations/issues).

## Follow the Userland Migrations Progression

You can follow the progress of userland migrations on our [GitHub project board](https://github.com/orgs/nodejs/projects/13/views/1).

This board tracks:

- Codemod kind (deprecation, breaking change, ecosystem)
- Node.js version
- Status (backlog, todo, in progress, done, not planned) _If you want to contribute, please check the "todo" column_
123 changes: 123 additions & 0 deletions apps/site/pages/en/learn/userland-migrations/v14-to-v16.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: Node.js v14 to v16
layout: learn
authors: AugustinMauroy
---

# Node.js v14 to v16

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

## `create-require-from-path`

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.

So this codemod handle [DEP0130](https://nodejs.org/api/deprecations.html#DEP0130).

```bash
npx codemod run @nodejs/create-require-from-path
```

### Example:

```js displayName="Before"
import { createRequireFromPath } from 'node:module';

// Using createRequireFromPath
const requireFromPath = createRequireFromPath('/path/to/module');
const myModule = requireFromPath('./myModule.cjs');
```

```js displayName="After"
import { createRequire } from 'node:module';

// Using createRequire with a specific path
const require = createRequire('/path/to/module');
const myModule = require('./myModule.cjs');
```

## `process-main-module`

The `process.mainModule` property was deprecated in favor of `require.main`. This codemod will help you replace the old `process.mainModule` usage with the new `require.main` usage.

So the codemod handle [DEP0138](https://nodejs.org/api/deprecations.html#DEP0138).

```bash
npx codemod run @nodejs/process-main-module
```

### Example:

```js displayName="Before"
if (process.mainModule === 'mod.js') {
// cli thing
} else {
// module thing
}
```

```js displayName="After"
if (require.main === 'mod.js') {
// cli thing
} else {
// module thing
}
```

## `rmdir`

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.

so this codemod handle [DEP0147](https://nodejs.org/api/deprecations.html#DEP0147).

```bash
npx codemod run @nodejs/rmdir
```

### Example:

```js displayName="Before"
// Using fs.rmdir with the recursive option
fs.rmdir(path, { recursive: true }, callback);

// Using fs.rmdirSync with the recursive option
fs.rmdirSync(path, { recursive: true });

// Using fs.promises.rmdir with the recursive option
fs.promises.rmdir(path, { recursive: true });
```

```js displayName="After"
// Using fs.rm with recursive and force options
fs.rm(path, { recursive: true, force: true }, callback);

// Using fs.rmSync with recursive and force options
fs.rmSync(path, { recursive: true, force: true });

// Using fs.promises.rm with recursive and force options
fs.promises.rm(path, { recursive: true, force: true });
```

## `tmpDir-to-tmpdir`

The `tmpDir` function was renamed to `tmpdir` in Node.js v16. This codemod will help you replace all instances of `tmpDir` with `tmpdir`.

So the codemod handles [DEP0022](https://nodejs.org/docs/latest/api/deprecations.html#dep0022-ostmpdir).

```bash
npx codemod run @nodejs/tmpDir-to-tmpdir
```

### Example:

```js displayName="Before"
import { tmpDir } from 'node:os';

const foo = tmpDir();
```

```js displayName="After"
import { tmpdir } from 'node:os';

const foo = tmpdir();
```
31 changes: 31 additions & 0 deletions apps/site/pages/en/learn/userland-migrations/v20-to-v22.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Node.js v20 to v22
layout: learn
authors: AugustinMauroy
---

# Node.js v20 to v22

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

## `import-assertions-to-attributes`

During the process of TC39 standardization, the `import assert` feature was introduced to allow importing [JSON modules](https://tc39.es/proposal-json-modules/) but during the during the transition to stage 4, the `assert` keyword was removed and replaced with an `with` attribute on the `import` statement.

So in [node.js v22](https://nodejs.org/fr/blog/release/v22.0.0#other-notable-changes), the `import assert` feature was removed and you need to use the `with` attribute instead.

Also note that the `with` keyword as been introduce in [node.js v18.20](https://nodejs.org/fr/blog/release/v18.20.0#added-support-for-import-attributes) but it was not mandatory until v22.

```bash
npx codemod run @nodejs/import-assertions-to-attributes
```

### Example:

```js displayName="Before"
import jsonData from './data.json' assert { type: 'json' };
```

```js displayName="After"
import jsonData from './data.json' with { type: 'json' };
```
47 changes: 47 additions & 0 deletions apps/site/pages/en/learn/userland-migrations/v22-to-v24.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Node.js v22 to v24
layout: learn
authors: AugustinMauroy
---

# Node.js v22 to v24

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

```js displayName="Before"
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 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);
```

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

### Example:

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

util.log('Hello world');
```

```js displayName="After"
console.log(new Date().toLocaleString(), 'Hello world');
```
10 changes: 7 additions & 3 deletions packages/i18n/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@
"acceptInputFromTheCommandLineInNodejs": "Accept input from the command line in Node.js"
}
},
"migrations": {
"userland-migrations": {
"links": {
"migrations": "Userland Migrations",
"introduction": "Introduction to Userland Migrations"
"userland-migrations": "Userland Migrations",
"introduction": "Introduction to Userland Migrations",
"ecosystem": "Ecosystem to Node.js",
"v22-to-v24": "Node.js v22 to v24",
"v20-to-v22": "Node.js v20 to v22",
"v14-to-v16": "Node.js v14 to v16"
}
},
"modules": {
Expand Down
Loading