Super Simple Web Server
Super Simple Web Server (super-simple-web-server) is a lightweight Node.js CLI utility designed for quickly serving static files via HTTP and HTTPS on localhost, primarily intended for development and testing purposes. Currently at version 1.1.4, with its last major update in March 2021, the package is in a maintenance state, fulfilling its specific niche without active feature development or a regular release cadence. A key feature is the inclusion of pre-generated, self-signed SSL certificates for HTTPS support, explicitly noted to be unsuitable for production environments and set to expire on June 6, 2028. It distinguishes itself by offering a "fire-and-forget" setup via `npm start` with optional command-line arguments for web root and custom CommonJS middleware, making it ideal for rapid prototyping or isolated local development without complex server configurations. While primarily a CLI tool, it also exposes a programmatic `startServer` function for more controlled integration within Node.js applications.
Common errors
-
Error: listen EADDRINUSE: address already in use :::3000
cause The default HTTP port (3000) or HTTPS port (3001) is already in use by another application on your system.fixSpecify different ports using environment variables: `SSWS_HTTP_PORT=8080 SSWS_HTTPS_PORT=8443 npm start`. -
Error: Cannot find module 'path/to/some/middleware'
cause The path provided for the middleware file is incorrect or the file does not exist at the specified location.fixVerify the absolute or relative path to your middleware file. Ensure the file exists and is accessible from where you run `npm start`. -
TypeError: app.use is not a function
cause This error typically occurs within a custom middleware file if the `app` object (the Express application instance) is not correctly received or used, or if the middleware file does not export a function in the expected CommonJS format.fixEnsure your middleware file has `module.exports = (app) => { /* ... */ };` and that `app` is correctly passed and used within your function (e.g., `app.use(...)`, `app.get(...)`).
Warnings
- gotcha This package includes self-signed SSL certificates for HTTPS support that will expire on June 6, 2028. These certificates are for development convenience ONLY and are explicitly NOT suitable for production use due to security risks.
- gotcha The server's `index.js` explicitly states 'Don't use this for production'. It is designed for simplicity and quick local development, lacking production-grade security, performance, and monitoring features.
- gotcha Custom middleware files must strictly use CommonJS `module.exports`. Attempting to use ES Modules (`export default` or named `export`) in middleware files will result in runtime errors.
- gotcha By default, the server binds to `127.0.0.1` (localhost). To bind to other available IP addresses on your machine, you must modify `index.js` directly by setting `USE_LOCALHOST = false`. This is not configurable via CLI arguments or environment variables.
Install
-
npm install super-simple-web-server -
yarn add super-simple-web-server -
pnpm add super-simple-web-server
Imports
- startServer
import { startServer } from 'super-simple-web-server';const { startServer } = require('super-simple-web-server'); - Full Module Object
const ssws = require('super-simple-web-server'); ssws.startServer(process.cwd(), null, { httpPort: 3000, httpsPort: 3001 }); - Middleware Function
export default (app) => { /* ... */ };module.exports = (app) => { app.use((req, res, next) => { console.log('Middleware activated for:', req.url); next(); }); // Example: Add a custom route app.get('/hello', (req, res) => res.send('Hello from custom middleware!')); };
Quickstart
npm install super-simple-web-server
# To serve files from the current directory on default ports (HTTP 3000, HTTPS 3001)
npm start
# To serve files from a specific directory, e.g., './public'
npm start ./public
# Create a middleware.js file:
# // middleware.js
# module.exports = (app) => {
# app.get('/api/data', (req, res) => res.json({ message: 'Data from API', timestamp: Date.now() }));
# };
# To serve files from './public' with custom middleware from './middleware.js'
npm start ./public ./middleware.js
# To change default ports, e.g., HTTP on 8080, HTTPS on 8443
SSWS_HTTP_PORT=8080 SSWS_HTTPS_PORT=8443 npm start