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: 1 addition & 1 deletion apps/site/authors.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"name": "Richard Lau",
"website": "https://github.com/richardlau"
},
"Richie McColl": {
"richiemccoll": {
"id": "richiemccoll",
"name": "Richie McColl",
"website": "https://github.com/richiemccoll"
Expand Down
160 changes: 160 additions & 0 deletions apps/site/pages/en/blog/migrations/axios-to-fetch.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
---
date: '2026-05-09T00:00:00.000Z'
category: migrations
title: Axios to WHATWG Fetch
layout: blog-post
author: AugustinMauroy
---

# Migrate from Axios to WHATWG Fetch

This codemod transforms code using [Axios](https://github.com/axios/axios) to leverage the [WHATWG Fetch API](https://fetch.spec.whatwg.org/), which is now natively available in Node.js.

## Why doing this?

- **Native Support**: Fetch is built into Node.js, eliminating the need for external libraries and their associated maintenance overhead.
- **Improved Performance**: Fetch is optimized for modern JavaScript runtimes, often resulting in better performance compared to Axios.
- **Better Standards Compliance**: Fetch adheres closely to web standards, making it easier to write cross-platform code that works both in Node.js and browsers.
- **Reduced Security Risks**: Removing Axios eliminates potential vulnerabilities associated with third-party dependencies, enhancing the security of your application.

## Node.js Version Requirements

- Node.js v18.0.0 or later (Fetch API is available but marked experimental)
- Node.js v21.0.0 or later (Fetch API is stable)

> If your package currently supports Node.js versions earlier than v18.0.0, you cannot migrate to the Fetch API without dropping support for those versions.
> This requires bumping the major version of your package AND updating the engines field in your package.json to require Node.js >= v18.0.0.

## Supported Transformations

The codemod supports the following Axios methods and converts them to their Fetch equivalents:

- `axios.request(config)`
- `axios.get(url[, config])`
- `axios.delete(url[, config])`
- `axios.head(url[, config])`
- `axios.options(url[, config])`
- `axios.post(url[, data[, config]])`
- `axios.put(url[, data[, config]])`
- `axios.patch(url[, data[, config]])`
- `axios.postForm(url[, data[, config]])`
- `axios.putForm(url[, data[, config]])`
- `axios.patchForm(url[, data[, config]])`

## Examples

### GET Request

```diff
const base = 'https://dummyjson.com/todos';

- const all = await axios.get(base);
+ const all = await fetch(base).then(async (res) => Object.assign(res, { data: await res.json() })).catch(() => null);
console.log('\nGET /todos ->', all.status);
console.log(`Preview: ${all.data.todos.length} todos`);
```

### POST Request

```diff
const base = 'https://dummyjson.com/todos';

- const created = await axios.post(
- `${base}/add`, {
- todo: 'Use DummyJSON in the project',
- completed: false,
- userId: 5,
- }, {
- headers: { 'Content-Type': 'application/json' }
- }
- );
+ const created = await fetch(`${base}/add`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ todo: 'Use DummyJSON in the project',
+ completed: false,
+ userId: 5,
+ }),
+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
console.log('\nPOST /todos/add ->', created.status);
console.log('Preview:', created.data?.id ? `created id ${created.data.id}` : JSON.stringify(created.data).slice(0,200));
```

### POST Form Request

```diff
const formEndpoint = '/submit';

- const created = await axios.postForm(formEndpoint, {
- title: 'Form Demo',
- completed: false,
- });
+ const created = await fetch(formEndpoint, {
+ method: 'POST',
+ body: new URLSearchParams({
+ title: 'Form Demo',
+ completed: false,
+ }),
+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
console.log('Preview:', created.data);
```

### PUT Request

```diff
const base = 'https://dummyjson.com/todos';

- const updatedPut = await axios.put(
- `${base}/1`,
- { completed: false },
- { headers: { 'Content-Type': 'application/json' } }
- );
+ const updatedPut = await fetch(`${base}/1`, {
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ completed: false }),
+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
console.log('\nPUT /todos/1 ->', updatedPut.status);
console.log('Preview:', updatedPut.data?.completed !== undefined ? `completed=${updatedPut.data.completed}` : JSON.stringify(updatedPut.data).slice(0,200));
```

### DELETE Request

```diff
const base = 'https://dummyjson.com/todos';

- const deleted = await axios.delete(`${base}/1`);
+ const deleted = await fetch(`${base}/1`, { method: 'DELETE' })
+ .then(async (res) => Object.assign(res, { data: await res.json() }));
console.log('\nDELETE /todos/1 ->', deleted.status);
console.log('Preview:', deleted.data ? JSON.stringify(deleted.data).slice(0,200) : typeof deleted.data);
```

### `request` Axios Method

```diff
const base = 'https://dummyjson.com/todos';

- const customRequest = await axios.request({
- url: `${base}/1`,
- method: 'PATCH',
- headers: { 'Content-Type': 'application/json' },
- data: { completed: true },
- });
+ const customRequest = await fetch(`${base}/1`, {
+ method: 'PATCH',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ completed: true }),
+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
console.log('\nPATCH /todos/1 ->', customRequest.status);
console.log('Preview:', customRequest.data?.completed !== undefined ? `completed=${customRequest.data.completed}` : JSON.stringify(customRequest.data).slice(0,200));
```

## Unsupported APIs

The codemod does not yet cover Axios features outside of direct request helpers, such as interceptors, cancel tokens, or instance configuration from `axios.create()`.

## Recognition

We would like to thank the maintainers of [Axios](https://github.com/axios/axios) for their support of the package over time and for its contributions to the ecosystem.
46 changes: 16 additions & 30 deletions apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ author: richiemccoll

# Migrate from Chalk to Node.js util styleText

## `chalk-to-util-styletext`

This codemod aims to help you reduce external dependencies by transforming chalk method calls to use the native Node.js styling functionality. It will also handle automatic removal of the [`chalk`](https://github.com/chalk/chalk) package from the package.json.

### Compatible Features:
## Compatible Features:

- Basic colors (red, green, blue, yellow, etc.)
- Bright colors (redBright, greenBright, etc.)
Expand All @@ -21,24 +19,22 @@ This codemod aims to help you reduce external dependencies by transforming chalk
- Style chaining via array syntax
- Environment variable support (NO_COLOR, NODE_DISABLE_COLORS, FORCE_COLOR)

### Incompatible Features:
## Incompatible Features:

- Custom RGB colors (chalk.rgb(), chalk.hex())
- 256-color palette (chalk.ansi256())
- Template literal syntax (chalk...``)
- Advanced modifiers with limited terminal support (overline, blink, etc.)

### Prerequisites:

#### Node.js Version Requirements
## Node.js Version Requirements

- Node.js v20.12.0 or later (for util.styleText)
- `util.styleText` became stable in Node.js v22.13.0 (and v23.5.0)

> If your package currently supports Node.js versions earlier than v20.12.0, you cannot migrate to util.styleText without dropping support for those versions.
> This requires bumping the major version of your package AND updating the engines field in your package.json to require Node.js >= v20.12.0.

### Usage:
## Usage:

The source code for this codemod can be found in the [chalk-to-util-styletext directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/chalk-to-util-styletext).

Expand All @@ -48,33 +44,23 @@ You can find this codemod in the [Codemod Registry](https://app.codemod.com/regi
npx codemod @nodejs/chalk-to-util-styletext
```

### Example:
## Example:

```js displayName="Before"
import chalk from 'chalk';
```diff
- import chalk from 'chalk';
+ import { styleText } from 'node:util';

console.log(chalk.red('Error message'));
- console.log(chalk.red('Error message'));
+ console.log(styleText('red', 'Error message'));

console.log(chalk.red.bold('Important error'));
- console.log(chalk.green.underline('Success with emphasis'));
+ console.log(styleText(['green', 'underline'], 'Success with emphasis'));

const red = chalk.red;
- const red = chalk.red;
+ const red = (text) => styleText('red', text);
- const boldBlue = chalk.blue.bold;
+ const boldBlue = (text) => styleText(['blue', 'bold'], text);
console.log(red('Error'));

const boldBlue = chalk.blue.bold;
console.log(boldBlue('Info'));
```

```js displayName="After"
import { styleText } from 'node:util';

console.log(styleText('red', 'Error message'));

console.log(styleText(['red', 'bold'], 'Important error'));

const red = text => styleText('red', text);
console.log(red('Error'));

const boldBlue = text => styleText(['blue', 'bold'], text);
console.log(boldBlue('Info'));
```

Expand Down
27 changes: 12 additions & 15 deletions apps/site/pages/en/blog/migrations/v12-to-v14.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,20 @@ The source code for this codemod can be found in the [util-print-to-console-log
You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/util-print-to-console-log).

```bash
npx codemod run @nodejs/create-require-from-path
npx codemod run @nodejs/util-print-to-console-log
```

### Example:

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

util.print('Hello world');
util.puts('Hello world');
util.debug('Hello world');
util.error('Hello world');
```

```js displayName="After"
console.log('Hello world');
console.log('Hello world');
console.error('Hello world');
console.error('Hello world');
```diff
- const util = require("node:util");

- util.print("Hello world");
+ console.log("Hello world");
- util.puts("Hello world");
+ console.log("Hello world");
- util.debug("Hello world");
+ console.error("Hello world");
- util.error("Hello world");
+ console.error("Hello world");
```
Loading
Loading