Pushstate Server

3.1.0 · maintenance · verified Sun Apr 19

Pushstate Server is a minimalistic static file server designed to work seamlessly with HTML5 Pushstate, a browser API for manipulating browser history. It addresses the common single-page application (SPA) routing problem where direct access to a deep link (e.g., `/users/123`) would result in a 404 error because no physical file exists at that path on the server. Instead, this server is configured to return the `index.html` file for any route that does not directly map to a static asset. Conversely, requests for actual static files (e.g., `/assets/logo.png`) are served directly. The package is currently at version 3.1.0. Its release cadence appears to be very slow or effectively ceased, with the last publish on npm dating back over seven years to February 12, 2019. Key differentiators include its simple configuration for HTML5 Pushstate routing, supporting multiple directories for serving static assets, and binding to specific hosts or ports. It remains a lightweight solution for basic SPA hosting needs, though its lack of recent updates may pose compatibility or security considerations for modern development workflows.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize and start the pushstate-server for serving static files from a single directory.

const server = require('pushstate-server');

// Start a server for a single directory
server.start({
  port: process.env.PORT ?? 3000,
  directory: './public'
});

console.log(`Server started on port ${process.env.PORT ?? 3000} serving './public'.`);
console.log('Access your single-page app at http://localhost:3000');
console.log('e.g., http://localhost:3000/some/pushstate/route will serve index.html');

// Or for multiple directories
// server.start({
//   port: process.env.ANOTHER_PORT ?? 4200,
//   directories: ['./dist', './node_modules']
// });

view raw JSON →