
Node.js 22.12+ · CommonJS + ESM · localhost first
Start a static server.
Serve files over HTTP or HTTPS with ranges, cache validation, optional compression, clean shutdown, and zero runtime dependencies.
CLI quick start
Serve a folder locally.
Install the command globally, or use npx. The default listener is reachable only from this machine.
npm install --global node-http-server
node-http-server --root ./publicnode-http-server listening at http://127.0.0.1:8080
npx node-http-server --root ./public. See the CLI task guide for flags, failures, exit behavior, and deployment examples.Library quick start
Create an isolated server.
const {Server}=require('node-http-server');
new Server({root:'./public'}).deploy();import {Server} from 'node-http-server';
new Server({root:'./public'}).deploy();The original default singleton remains available in both module systems. New applications should normally create a named Server instance so listener and configuration state stay isolated.
Starting behavior
Know the defaults before changing them.
| Behavior | Default | Change it |
|---|---|---|
| Request-body limit | Unlimited | server.maxRequestBodyBytes |
| Compression | Off | server.compression |
| SPA fallback | Off | server.spaFallback |
| Dotfiles | Blocked with 403 | server.allowDotfiles |
| Automatic MIME types | Built-in map | contentType |
| Request logging | Off | log |
| HTTPS | Off | https |
host:'0.0.0.0' or --host 0.0.0.0 only when other machines should connect. Read Operations and security first.Documentation by task
Go directly to the job.
Install, flags, common tasks, expected output, and failure behavior.
CLI → Embed the serverImports, lifecycle, public methods, request data, and hooks.
Library API → Set exact behaviorEvery Config key, default, opt-out value, and validation rule.
Configuration → Copy a working patternSPA, HTTPS, domains, logging, hooks, limits, and shutdown.
Examples → Generate a configBuild CommonJS, ESM, CLI, or JSON without running a server.
Playground → Test and measureTest commands, coverage gates, reports, badges, and CI artifacts.
Testing → Operate or upgradeExposure, status failures, logging, certificates, and v8 migration.
Operations → Browse the docs hubA compact map of every page and the source documents.
Docs hub →Project status