Basic Node Server

A small static file server for local hosting and quick testing.
It serves files from your current working directory (or a configured root) over HTTP.
If the request path is / (or ends with /), it serves index.html.
It only serves files inside the configured root directory and supports conditional caching via ETag and Last-Modified (304 Not Modified).

Installation

npm install basic-node-server

Quick Start

npx bns

Default port is 3000.

Usage

npx bns [port=<number>] [root=<dir>] [404=<file>] [no-cache=true]

Show CLI help:

npx bns --help

Options

Examples

# Serve current directory on port 3000
npx bns

# Serve on port 8080
npx bns port=8080

# Serve a specific directory
npx bns root=./public

# Use a custom 404 page
npx bns port=8080 404=notfound.html

# Disable caching headers
npx bns no-cache=true port=8080

# Custom 404 + no-cache
npx bns 404=notfound.html no-cache=true port=8080

Request Behavior