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

@hardlydifficult/http

v1.0.23

Published

Opinionated HTTP helpers for small Node servers. The API is intentionally narrow: - request bodies default to a 1 MB limit - JSON responses default to `200` with CORS open to `*` - constant-time comparison accepts nullable values and fails closed on missi

Readme

@hardlydifficult/http

Opinionated HTTP helpers for small Node servers. The API is intentionally narrow:

  • request bodies default to a 1 MB limit
  • JSON responses default to 200 with CORS open to *
  • constant-time comparison accepts nullable values and fails closed on missing tokens

Installation

npm install @hardlydifficult/http

Quick Start

import http from "http";
import { json, readJson, safeCompare } from "@hardlydifficult/http";

const server = http.createServer(async (req, res) => {
  const body = await readJson<{ token?: string }>(req);

  if (!safeCompare(body.token, "secret-token")) {
    json(res, { error: "Unauthorized" }, { status: 401 });
    return;
  }

  json(res, { success: true });
});

server.listen(3000);

Request Helpers

readBody

Reads the full HTTP request body as a string.

function readBody(
  req: IncomingMessage,
  options?: { maxBytes?: number }
): Promise<string>
import { readBody } from "@hardlydifficult/http";

const body = await readBody(req);
const smallBody = await readBody(req, { maxBytes: 500 * 1024 });

readJson

Reads and parses a JSON request body.

function readJson<T>(
  req: IncomingMessage,
  options?: { maxBytes?: number }
): Promise<T>

Throws "Invalid JSON body" when parsing fails.

import { readJson } from "@hardlydifficult/http";

const payload = await readJson<{ name: string }>(req);

MAX_BODY_BYTES

The default maximum body size.

import { MAX_BODY_BYTES } from "@hardlydifficult/http";

console.log(MAX_BODY_BYTES); // 1048576

Response Helpers

json

Short alias for sending a JSON response.

function json(
  res: ServerResponse,
  body: unknown,
  options?: { status?: number; corsOrigin?: string }
): void
import { json } from "@hardlydifficult/http";

json(res, { ok: true });
json(res, { error: "Unauthorized" }, { status: 401 });
json(res, { id: 1 }, { corsOrigin: "https://trusted.com" });

sendJson

Identical to json if you prefer the longer name.

Security

safeCompare

Constant-time string comparison for secrets and tokens. Missing values never match.

function safeCompare(
  a: string | null | undefined,
  b: string | null | undefined
): boolean
import { safeCompare } from "@hardlydifficult/http";

if (safeCompare(request.headers.authorization, process.env.API_TOKEN)) {
  // Grant access
}