local-web-server is a lean, modular web server designed for rapid full-stack development. As a distribution of the core `lws` package, it bundles a starter pack of useful middleware, enabling functionalities like serving static files, Single Page Applications (SPAs), URL rewriting, CORS, and mock APIs out-of-the-box. The current stable version is 5.4.0, with regular updates addressing bug fixes and new features. It supports HTTP, HTTPS, and HTTP2, offering both programmatic and command-line interfaces. Key differentiators include its small footprint, modular design allowing users to load only required behaviors, and comprehensive features for prototyping back-end services or front-end applications. It requires Node.js v12.20 or newer.
npm install local-web-serverVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates programmatically configuring a local web server for SPA routing, API rewriting, CORS, and logging.
Upgrade Node.js to v12.20 or newer. Check your `node` version with `node -v`.
Refactor your application to use ES module `import` syntax (e.g., `import createServer from 'local-web-server';`) and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
Always use the full `lws-` prefixed name for middleware plugins (e.g., `--stack lws-static`).
For WebSockets, implement a custom middleware. Consult the `lws` wiki for examples on creating middleware for specific functionalities.
Upgrade to local-web-server v5.4.0 or newer. If upgrading is not immediately possible, consider configuring the remote server to not set `Secure` or `SameSite=none` cookies for development environments, or use HTTPS locally if possible.
Ensure your file is treated as an ES module by using a `.mjs` extension or by adding `"type": "module"` to your `package.json`. If using an older Node.js version, upgrade to v12.20+.
Specify a different port using the `--port` CLI option or `port` configuration property (e.g., `ws --port 3000`). Alternatively, identify and terminate the process currently using the port.
Use the `--spa index.html` CLI option or `spa: 'index.html'` configuration property to tell local-web-server to serve `index.html` for non-existent file paths, allowing client-side routers to take over.
Install the required `lws-*` middleware packages (e.g., `npm install lws-static`) into your project dependencies. local-web-server only includes a default set; custom stacks require explicit installation.
No dependency data recorded yet.