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

fetchuri

v0.0.1

Published

Universal URI content fetcher (http/https/file/data) for Node.js and browsers

Readme

fetchuri

Universal content fetcher for any URI type (http/https/file/data) that works in both Node.js and browsers.

Installation

npm install fetchuri

# Or install globally for CLI usage
npm install -g fetchuri

CLI Usage

# Fetch any URI from the command line
fetchuri https://api.github.com/users/github

# Set Accept header for content negotiation
fetchuri https://api.example.com/data --accept application/json

# Add custom headers
fetchuri https://api.example.com --header "Authorization: Bearer token123"
fetchuri https://api.example.com -H "User-Agent: fetchuri/0.0.1" -H "Accept: text/html"

# Pretty-print JSON
fetchuri https://api.example.com/data.json --json

# Save to file
fetchuri https://example.com --output index.html

# Fetch local file
fetchuri file:///etc/hosts

# Decode data URI
fetchuri "data:text/plain,Hello%20World"

# Show help
fetchuri --help

Library Usage

import fetchuri from 'fetchuri'

// Fetch from HTTP/HTTPS
const html = await fetchuri('https://example.com')
const json = await fetchuri('https://api.example.com/data.json')

// With Accept header for content negotiation
const jsonData = await fetchuri('https://api.example.com/data', {
  headers: { 'Accept': 'application/json' }
})

// With custom headers
const response = await fetchuri('https://api.example.com/data', {
  headers: {
    'Accept': 'application/json',
    'Authorization': 'Bearer token123',
    'User-Agent': 'MyApp/1.0'
  }
})

// Fetch from local file
const config = await fetchuri('file:///home/user/config.json')

// Fetch from data URI
const inline = await fetchuri('data:text/plain,Hello%20World')
const base64 = await fetchuri('data:application/json;base64,eyJ0ZXN0Ijp0cnVlfQ==')

// No protocol defaults to HTTPS
const page = await fetchuri('example.com')  // → https://example.com

API

fetchuri(uri: string, options?: object): Promise<string>

Fetches content from any URI and returns it as a string.

Parameters:

  • uri - The URI to fetch (required)
  • options - Optional configuration object
    • headers - Custom headers for HTTP/HTTPS requests

Supported protocols:

  • http:// - HTTP URLs (Node.js & Browser)
  • https:// - HTTPS URLs (Node.js & Browser)
  • file:// - Local file paths (Node.js only)
  • data: - Data URIs (RFC 2397) (Node.js & Browser)

Error Handling

try {
  const content = await fetchuri('invalid://uri')
} catch (error) {
  console.error('Fetch failed:', error.message)
}

Browser vs Node.js

This module works in both environments with these differences:

  • Browser: Supports http://, https://, and data: protocols
  • Node.js: Supports all protocols including file://
  • Uses native fetch() in browsers, node-fetch in Node.js
  • Automatically detects the environment

Use Cases

  • Fetching JSON from APIs (universal)
  • Loading local configuration files (Node.js)
  • Reading HTML pages (universal)
  • Processing data URIs from HTML (universal)
  • Universal content loader for CLI tools and web apps

License

MIT