npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hnrie/nanofetch

v0.1.4

Published

Nano-sized, type-safe HTTP client. Axios-like API, zero dependencies, powered by native fetch.

Downloads

519

Readme

nanofetch

Nano-sized, type-safe HTTP client. Axios-like API, zero dependencies, powered by native fetch.

npm version License: MIT

Why nanofetch?

  • Lightweight - ~5KB package size, zero dependencies
  • Zero dependencies - No supply chain vulnerabilities
  • Axios-compatible API - Easy migration from Axios
  • TypeScript first - Full type safety and autocomplete
  • Universal - Works in browsers, Node.js, and React Native
  • Modern - Built on native fetch API

Installation

npm install nanofetch

Quick Start

import { api } from 'nanofetch';

// GET request
const response = await api.get('https://api.example.com/users');
console.log(response.data);

// POST request
await api.post('https://api.example.com/users', {
  name: 'John Doe',
  email: '[email protected]'
});

Usage

Basic Requests

import { api } from 'nanofetch';

// GET
const users = await api.get('/users');

// POST
const newUser = await api.post('/users', { name: 'Jane' });

// PUT
const updated = await api.put('/users/1', { name: 'Jane Doe' });

// PATCH
const patched = await api.patch('/users/1', { email: '[email protected]' });

// DELETE
await api.delete('/users/1');

Query Parameters

const response = await api.get('/users', {
  params: {
    page: 1,
    limit: 10,
    sort: 'name'
  }
});
// Requests: /users?page=1&limit=10&sort=name

Custom Headers

const response = await api.get('/protected', {
  headers: {
    'Authorization': 'Bearer your-token-here',
    'X-Custom-Header': 'value'
  }
});

Request Timeout

const response = await api.get('/slow-endpoint', {
  timeout: 5000 // 5 seconds
});

Creating Custom Instances

import { createApiClient } from 'nanofetch';

const api = createApiClient({
  baseURL: 'https://api.example.com',
  headers: {
    'Authorization': 'Bearer token',
    'Content-Type': 'application/json'
  },
  timeout: 10000
});

// Now all requests use the baseURL
await api.get('/users'); // -> https://api.example.com/users
await api.post('/posts', data); // -> https://api.example.com/posts

TypeScript Support

interface User {
  id: number;
  name: string;
  email: string;
}

// Response is fully typed
const response = await api.get<User[]>('/users');
response.data.forEach(user => {
  console.log(user.name); // Full autocomplete!
});

Error Handling

import { api, ApiError } from 'nanofetch';

try {
  const response = await api.get('/users');
} catch (error) {
  if (error instanceof ApiError) {
    console.log('Status:', error.status);
    console.log('Response:', error.response?.data);
    
    if (error.isNetworkError) {
      console.log('Network error - check your connection');
    }
    
    if (error.isTimeout) {
      console.log('Request timed out');
    }
  }
}

API Reference

Request Config

interface ApiRequestConfig {
  baseURL?: string;           // Base URL for requests
  params?: Record<string, any>; // Query parameters
  headers?: Record<string, string>; // Custom headers
  timeout?: number;           // Request timeout in milliseconds
  signal?: AbortSignal;       // For manual cancellation
  responseType?: 'json' | 'text' | 'blob'; // Response type
}

Response Object

interface ApiResponse<T> {
  data: T;                    // Response data
  status: number;             // HTTP status code
  statusText: string;         // HTTP status text
  headers: Headers;           // Response headers
  config: ApiRequestConfig;   // Request config used
}

Error Object

class ApiError extends Error {
  status?: number;            // HTTP status code
  response?: ApiResponse;     // Full response object
  config?: ApiRequestConfig;  // Request config used
  isNetworkError: boolean;    // True if network failure
  isTimeout: boolean;         // True if request timed out
}

Migrating from Axios

nanofetch uses the same API as Axios for common operations:

// Axios
import axios from 'axios';
const response = await axios.get('/users', { params: { page: 1 } });

// nanofetch - identical!
import { api } from 'nanofetch';
const response = await api.get('/users', { params: { page: 1 } });

Key Differences

  • No interceptors yet - Coming in v0.2.0
  • No request cancellation tokens - Use native AbortController instead
  • No automatic retries - Coming in v0.3.0

Roadmap

  • [x] Core HTTP methods (GET, POST, PUT, PATCH, DELETE)
  • [x] Query parameters
  • [x] Custom headers
  • [x] Timeout support
  • [x] TypeScript support
  • [ ] Request/response interceptors
  • [ ] Retry logic with exponential backoff
  • [ ] Progress events for uploads/downloads
  • [ ] Request deduplication

License

MIT © Henry Taiwo

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Author

Built by Henry Taiwo - Full-stack engineer building tools for developers.