Node-Fetch

3.3.2 · active · verified Sat Apr 18

Node-Fetch brings the Web Fetch API to Node.js, providing a familiar interface for making HTTP requests in a Node.js environment. The current stable version is 3.3.2. Both the v3 (ESM-only) and v2 (CommonJS) branches are actively maintained, receiving regular bug fixes and occasional new features.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to make a basic GET request to an external API and parse the JSON response. It also includes error handling for network issues and non-OK HTTP statuses.

import fetch from 'node-fetch';

async function getTodoItem() {
  try {
    const response = await fetch('https://jsonplaceholder.typicode.com/todos/1');

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

    const data = await response.json();
    console.log('Fetched TODO item:', data);
  } catch (error) {
    console.error('Error fetching data:', error);
  }
}

getTodoItem();

view raw JSON →