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

@jsenv/server

v17.6.9

Published

A modern Node.js HTTP server with declarative routing, content negotiation, and WebSocket support

Readme

server npm package

A Node.js HTTP server with declarative routing, content negotiation, file serving, WebSocket and Server-Sent Events.

import { startServer } from "@jsenv/server";

await startServer({
  port: 8080,
  routes: [
    {
      endpoint: "GET *",
      fetch: () => new Response("Hello world"),
    },
  ],
});

Features

  • Declarative routing: "GET /users/:id", the first route returning a response wins
  • 404, 405, 406, 415 and OPTIONS responses derived from the routes
  • Content negotiation for media type, language, version and encoding
  • File serving with etag/mtime client cache and compression
  • WebSocket and Server-Sent Events, with a broadcast helper
  • HTTPS, with http → https redirection; http2 as an option
  • CORS, server timing and error pages as plugins
  • Host header check (DNS rebinding) and bounded request bodies
  • A route inspector at /.internal/route_inspector

Installation

npm install @jsenv/server

Requires Node.js 22.13.1 or higher.

Quick examples

API server

import { startServer } from "@jsenv/server";

await startServer({
  port: 3000,
  routes: [
    {
      endpoint: "GET /api/users",
      fetch: () => Response.json([{ id: 1, name: "John" }]),
    },
    {
      endpoint: "GET /api/users/:id",
      fetch: (request) =>
        Response.json({ id: request.params.id, name: "John" }),
    },
    {
      endpoint: "POST /api/users",
      acceptedMediaTypes: ["application/json"],
      fetch: async (request) => {
        const user = await request.json();
        return Response.json(user, { status: 201 });
      },
    },
  ],
});

Static file server

import { createFileSystemFetch, startServer } from "@jsenv/server";

await startServer({
  routes: [
    {
      endpoint: "GET *",
      fetch: createFileSystemFetch(import.meta.resolve("./public/"), {
        etagEnabled: true,
        compressionEnabled: true,
      }),
    },
  ],
});

HTTPS server

import { readFileSync } from "node:fs";
import { startServer } from "@jsenv/server";

await startServer({
  https: {
    certificate: readFileSync(new URL("./server.crt", import.meta.url), "utf8"),
    privateKey: readFileSync(new URL("./server.key", import.meta.url), "utf8"),
  },
  routes: [
    {
      endpoint: "GET *",
      fetch: () => new Response("Welcome"),
    },
  ],
});

Documentation

Every option is described by the JSDoc of the export (startServer, createFileSystemFetch, serverPluginCORS, …): hover it in your editor. The pages below explain how the pieces fit together.

| Topic | Description | | ---------------------------------------------------- | ------------------------------------------------------ | | Handling requests | Routes, the request object, the response formats | | Handling errors | What happens when a route throws, error pages | | Plugins | The hooks a server plugin can implement | | Serving files | Static files with client cache and compression | | Content negotiation | Media type, language, version and encoding negotiation | | WebSocket | Accepting WebSocket connections | | Server-Sent Events | Pushing events to clients | | CORS | Cross-Origin Resource Sharing | | HTTPS | HTTPS, http redirection and http2 | | Server timing | Reporting where the server spent its time | | Lifecycle | Starting, stopping, keeping the process alive | | Security | What the server protects, what it leaves to you | | Cluster | One server per CPU core |