http-server-spa is a lightweight and fast Node.js-based static file server specifically designed to host Single Page Applications (SPAs). Its primary feature is built-in support for the HTML5 History API fallback, which routes all non-file requests to a specified fallback HTML file (e.g., `index.html`), allowing client-side routers to handle URL paths without 404 errors. This differentiates it from general-purpose static servers that require additional configuration for this behavior. The package is predominantly a command-line interface (CLI) tool, commonly installed globally. While the npm metadata indicates version 1.3.0, the most recent "first official release" is tagged as 3.2.0, addressing several bug fixes including Node.js compatibility. Release cadence appears irregular, focusing on critical bug fixes and improvements rather than a fixed schedule. It distinguishes between "file requests" and "route requests," serving actual files with a 200 status or redirecting route requests to the fallback with a 301 status for non-root paths.
npm install http-server-spaVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to globally install `http-server-spa` and use its CLI to serve a basic single-page application, showcasing the history-api-fallback functionality for client-side routing and serving static assets.
Upgrade to `http-server-spa` version 3.2.0 or newer: `npm install -g http-server-spa@latest`.
Understand that the 301 status for non-root routes is intentional, indicating that the client-side router should handle the path after the redirect. Ensure your client-side application is robust to this redirect behavior.
Ensure you install the package globally via `npm install -g http-server-spa` or add the local `node_modules/.bin` directory to your system's PATH if you prefer a local installation.
Install the package globally using `npm install -g http-server-spa`. If already installed globally, ensure your npm global bin directory is in your system's PATH.
Verify that the first argument (directory path) and the second argument (fallback HTML file path) provided to `http-server-spa` correctly point to existing locations relative to where the command is executed, or absolute paths.
This is not an error to be fixed in the server, but an intended feature. Your client-side SPA router should be designed to handle these redirects and process the URL path on the client side after the initial page load.
No dependency data recorded yet.