Undici

8.1.0 · active · verified Sat Apr 18

Undici is a powerful HTTP/1.1 client written from scratch for Node.js, offering a modern API including a WHATWG `fetch` implementation. It is currently at version 8.1.0, with frequent patch and minor releases across its active major versions, often aligning with Node.js LTS cycles.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to perform a basic GET request using undici's `fetch` API and log the JSON response. This example fetches information about the 'nodejs' user from GitHub.

import { fetch } from 'undici';

async function fetchData() {
  try {
    const response = await fetch('https://api.github.com/users/nodejs', {
      headers: {
        'User-Agent': 'undici-example/1.0',
      },
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const data = await response.json();
    console.log('GitHub user:', data.login);
  } catch (error) {
    console.error('Failed to fetch data:', error);
  }
}

fetchData();

view raw JSON →