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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@jsenv/server

v16.3.4

Published

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

Readme

server npm package

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

@jsenv/server simplifies server development with a declarative API that handles common web server needs like routing, content negotiation, file serving, and real-time communication.

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

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

Features

  • [*] Declarative routing with path parameters and pattern matching
  • [*] Content negotiation for type, language, version and encoding
  • [*] Real-time communication via WebSockets and Server-Sent Events
  • [*] File serving with ETags, conditional requests, and compression
  • [*] Security with HTTPS and automatic HTTP-to-HTTPS redirection
  • [*] HTTP/2 support including server push
  • [*] CORS handling built-in
  • [*] Performance monitoring with server timing
  • [*] Sacalability through cluster mode for multi-core utilization
  • [ ] Request authentification with JWT, OAuth etc

Installation

npm install @jsenv/server

Requirements:

  • Node.js 22.13.1 or higher
  • ES modules support

Quick Examples

Basic API Server

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

await startServer({
  port: 3000,
  routes: [
    {
      endpoint: "GET /api/users",
      response: () => Response.json([{ id: 1, name: "John" }]),
    },
    {
      endpoint: "GET /api/users/:id",
      response: (request) =>
        Response.json({ id: request.params.id, name: "John" }),
    },
    {
      endpoint: "GET *",
      response: () => new Response("Not found", { status: 404 }),
    },
  ],
});

Static File Server

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

await startServer({
  routes: [
    {
      endpoint: "GET *",
      response: createFileSystemFetch(import.meta.resolve("./")),
    },
  ],
});

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"),
  },
  allowHttpRequestOnHttps: true, // will disable https redirection and let you handle http request
  routes: [
    {
      endpoint: "GET *",
      response: (request) => {
        const clientUsesHttp = request.origin.startsWith("http:");
        return new Response(
          clientUsesHttp ? `Welcome http user` : `Welcome https user`,
        );
      },
    },
  ],
});

Documentation

| Topic | Description | | ---------------------------------------------------- | ------------------------------------------------ | | Handling requests | Process HTTP requests and generate responses | | Handling errors | Error handling strategies and custom responses | | Server timing | Measure and report server performance metrics | | CORS | Configure Cross-Origin Resource Sharing | | HTTPS | Set up secure HTTPS connections | | Serving files | Static file serving with caching and compression | | Content negotiation | Content type, language and encoding negotiation | | Websocket | Bi-directional real-time communication | | Server Sent Events | Push updates to clients over HTTP | | Cluster | Scale your server across multiple CPU cores | | HTTP/2 Push | Optimize loading with server push |