Skip to content

node-fetch #269

@joaopedrodcf

Description

@joaopedrodcf

node-fetch

node-fetch was a package created for fetch to run in node ( similar to cross-fetch but cross-fetch is to work equal in browser and server ), it has still millions of downloads even if fetch since 18 ( experimental ) and 21 ( stable ) supports fetch API

Image

https://www.npmjs.com/package/node-fetch


description: Node Js supports fetch API since v21 and experimental with a flag since 18

Replacements for node-fetch

Native fetch API

The native fetch API is available in Node.js (since v18.x) and all modern browsers. For most HTTP requests, it can replace axios without extra dependencies.

Example:

// GET
const res = await fetch('https://api.example.com/data')
const data = await res.json()

// POST
await fetch('https://api.example.com/data', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ key: 'value' })
})

ky

ky is a lightweight HTTP client based on the Fetch API with timeout support, hooks (interceptors) and other helpers.

Example:

import ky from 'ky'

const api = ky.create({
  prefixUrl: 'https://api.example.com',
  timeout: 5000, // ms
})

const data = await api.get('users').json()

ofetch

ofetch s a fetch wrapper with automatic JSON parsing, request/response interceptors, and retries.

Example:

import { ofetch } from 'ofetch'

const api = ofetch.create({
  baseURL: 'https://api.example.com',
})

const data = await api('/user', { query: { id: 123 } })
const created = await api('/items', { method: 'POST', body: { name: 'A' } })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions