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 🙏

© 2024 – Pkg Stats / Ryan Hefner

fetch-enhanced

v12.3.0

Published

fetch wrapper with support for automatic HTTP proxy, timeout and accessible agent options

Downloads

9,448

Readme

fetch-enhanced

fetch-enhanced wraps a provided fetch-like function like undici or node-fetch and adds:

  • HTTP Proxy discovery from standard environment variables
  • HTTP Request Timeout support
  • Accessible agent/dispatcher options

Usage

import {fetch as undiciFetch} from "undici";
import fetchEnhanced from "fetch-enhanced";

const fetch = fetchEnhanced(undiciFetch, {undici: true});
await fetch("https://example.com");

API

fetchEnhanced(fetchImplementation, opts)

  • fetchImplementation: Function A fetch-like module that takes (url, opts) and a agent (like node-fetch) or dispatcher (like undici) option.
  • opts Object Required.
    • agentCacheSize: number Size of the agent cache. Default: 512.
    • undici: boolean Whether the fetch implementation is undici. Required.

Returns: A wrapped fetch function.

fetch(url, [opts])

  • opts Object
    • timeout: number Request timeout in milliseconds. Default: 0 (meaning no timeout).
    • noProxy: boolean Explicitely disable any proxy server use. Default: false.
    • agent: http.Agent Custom HTTP agent. When specified, proxy discovery will no longer work.
    • agentOpts: object Agent or Dispatcher options.Default: {maxSockets: 64, keepAlive: false}
      • agentOpts.noProxy: boolean Do not use proxy in any case. Default: false.
    • Any valid fetch module option, like for node-fetch

TimeoutError

Error class that can be used for err instanceof TimeoutError:

import {TimeoutError} from "fetch-enhanced";

try {
  await fetch("https://example.com", {timeout: 0});
} catch (err) {
  console.log(err instanceof TimeoutError);
  // => true
}

fetch.clearCache()

Clear the agent cache and destroys all cached agents. This is generally only neccessary when the proxy environment variables are expected to change during runtime.

process.env.HTTPS_PROXY = "https://proxy1.dev";
await fetch("https://example.com");
fetch.clearCache();
process.env.HTTPS_PROXY = "https://proxy2.dev";
await fetch("https://example.com");

© silverwind, distributed under BSD licence