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

streamfetch

v0.8.1

Published

A lightweight HTTP client for Node.js that supports streaming data, designed for lightweight AI applications.

Readme

StreamFetch

Welcome to StreamFetch – your new best friend for making HTTP requests in Node.js! If you’re looking for a lightweight, no-nonsense HTTP client with zero dependencies, you’ve come to the right place. Perfect for lightweight AI applications, StreamFetch is here to make your life easier.

Why StreamFetch?

Why choose StreamFetch over the gazillion other HTTP clients out there? Great question!

  • Super Simple: StreamFetch is so easy to use, even your grandma could do it (well, maybe not, but you get the point).
  • No Dependencies: I don’t believe in baggage. StreamFetch is dependency-free, which means it's lightweight and fast.
  • GET and POST Requests: Need to fetch data or send it? I've got you covered with simple methods for both.
  • Streaming Data: Handle streaming data like a pro with the optional onData callback.
  • Handles Redirects and Timeouts: I’ve thought of everything so you don’t have to.

Installation

Install StreamFetch with npm and get started in seconds:

npm install streamfetch

Usage

Basic Examples

Example 1: Simple GET Request

import { get } from "streamfetch";

// Perform a GET request
async function fetchData() {
	try {
		const response = await get("http://www.example.com");
		if (response.ok) {
			const data = await response.text();
			console.log(data);
		} else {
			console.error("Network response was not ok.");
		}
	} catch (error) {
		console.error("Fetch error:", error);
	}
}

fetchData();

Example 2: Streaming Data in an Express App from the Goq API

import express from "express";
import { get } from "streamfetch";

const app = express();

app.get("/stream-groq", async (req, res) => {
	try {
		await get("https://api.groq.com/openai/v1/chat/completions", {
			headers: {
				Authorization: `Bearer YOUR_OPENAI_API_KEY`,
				"Content-Type": "application/json",
			},
			body: JSON.stringify({
				messages: [
					{
						role: "user",
						content:
							"Explain the importance of fast language models",
					},
				],
				model: "llama3-8b-8192",
			}),
			onData: (chunk) => {
				res.write(chunk);
			},
		});
		res.end();
	} catch (error) {
		console.error("Fetch error:", error);
		res.status(500).send("An error occurred while fetching data");
	}
});

app.listen(3000, () => {
	console.log("Server is running on http://localhost:3000");
});

More Usage Examples

Perform a POST Request

import { post } from "streamfetch";

async function postData() {
	try {
		const response = await post(
			"https://jsonplaceholder.typicode.com/posts",
			{
				title: "foo",
				body: "bar",
				userId: 1,
			},
			{
				headers: {
					"Content-Type": "application/json",
				},
			}
		);
		if (response.ok) {
			const data = await response.json();
			console.log(data);
		} else {
			console.error("Network response was not ok.");
		}
	} catch (error) {
		console.error("Fetch error:", error);
	}
}

postData();

Handle Streaming Data

import { get } from "streamfetch";

async function fetchDataWithStream() {
	try {
		const chunks = [];
		await get("http://www.example.com", {
			onData: (chunk) => {
				console.log("Received chunk:", chunk);
				chunks.push(chunk.toString());
			},
		});
		console.log("Complete response:", chunks.join(""));
	} catch (error) {
		console.error("Fetch error:", error);
	}
}

fetchDataWithStream();

API

fetch(url, options)

Perform an HTTP request.

  • url (string): The URL to fetch.
  • options (object):
    • method (string): The HTTP method to use (default: 'GET').
    • headers (object): The headers to include in the request.
    • body (string|object): The body of the request for POST/PUT methods.
    • onData (function): Callback function to handle streaming data.
    • followRedirects (boolean): Whether to follow redirects automatically (default: true).
    • maxRedirects (number): Maximum number of redirects to follow (default: 5).
    • timeout (number): Timeout in milliseconds for the request.
    • signal (AbortSignal): Abort signal to cancel the request.

Returns: A promise that resolves to the response object.

get(url, options)

Perform a GET request.

  • url (string): The URL to fetch.
  • options (object): The options for the request.

Returns: A promise that resolves to the response object.

post(url, body, options)

Perform a POST request.

  • url (string): The URL to fetch.
  • body (object): The body of the request.
  • options (object): The options for the request.

Returns: A promise that resolves to the response object.

Running Tests

I've even made testing a breeze. To run the tests, ensure you have Jest installed and use the following command:

npm test

License

StreamFetch is proudly licensed under the MIT License. See the LICENSE file for more details.

Contributing

I love contributions! Found a bug? Have an idea for an enhancement? Open an issue or submit a pull request. Let’s make StreamFetch even better together!

Acknowledgements

StreamFetch was inspired by the need for a lightweight and flexible HTTP client for Node.js, particularly suited for lightweight AI applications. Because sometimes, you just want things to work without the bloat.

Happy fetching! 🚀