Superstatic Static File Server
Superstatic is an enhanced static web server designed for modern web applications, currently at version 10.0.0. Originally built to power Firebase Hosting, it provides robust features such as HTML5 pushState support, clean URLs (removing `.html` extensions), advanced caching, and configurable routing via rewrites and redirects. It offers a flexible configuration system through `superstatic.json` or `firebase.json` files. The project maintains an active release cadence, frequently updating dependencies and Node.js engine support, with recent versions focusing on compatibility with newer Node.js LTS releases. Key differentiators include its rich configuration options for dynamic static site behavior, strong support for Single Page Applications (SPAs), and its historical role in Firebase's infrastructure.
Common errors
-
Error: Cannot GET / (or other path) / 404 Not Found
cause The requested file or path does not exist in the configured `public` directory, or the `public` directory is misconfigured.fixVerify that your `public` configuration setting in `superstatic.json` or `firebase.json` correctly points to the directory containing your static assets, relative to the configuration file, and that the requested file exists. -
TypeError: config.cleanUrls.includes is not a function
cause Attempting to use an array for the `cleanUrls` configuration option, which is no longer supported.fixSet `cleanUrls` to a boolean value (`true` or `false`) in your `superstatic.json` or `firebase.json` file. Array support for `cleanUrls` was removed in v6.0.0. -
Node.js version not supported. Superstatic requires Node.js 20 || 22 || 24.
cause You are running an unsupported version of Node.js.fixUpgrade your Node.js runtime environment to one of the officially supported LTS versions (20, 22, or 24). You can use a tool like `nvm` to manage Node.js versions. -
Error: Cannot redirect to an empty string
cause A `redirects` rule is configured with an empty or invalid `destination` property, or a source pattern results in an empty segment for the destination.fixReview your `redirects` configuration in `superstatic.json` or `firebase.json` and ensure all `destination` paths are valid and non-empty. Pay special attention to segmented redirects (`:segment`) to ensure they resolve correctly.
Warnings
- breaking The `cleanUrls` configuration option no longer accepts an array of globs; it must be a boolean value (`true` or `false`).
- breaking Node.js 10 support has been dropped. Running Superstatic on Node.js 10 will likely result in errors or unexpected behavior.
- breaking Node.js 18 support has been removed. Superstatic now requires Node.js 20, 22, or 24.
- gotcha Unicode paths in redirects may not have been handled correctly in earlier versions.
- gotcha The internal URL parsing mechanism switched from `fast-url-parser` to Node.js's built-in URL parser. This change could introduce subtle behavioral differences for highly specific or edge-case URL structures.
- gotcha In Node.js 22, the `mtime` property from `fs.stat` was sometimes unavailable. This was fixed in `superstatic` v9.1.0.
Install
-
npm install superstatic -
yarn add superstatic -
pnpm add superstatic
Imports
- Server
const Server = require('superstatic');import { Server } from 'superstatic'; - superstatic cli (global)
import superstatic from 'superstatic';
npm install -g superstatic
- Server (CommonJS)
const Server = require('superstatic').default;const { Server } = require('superstatic');
Quickstart
import { Server } from 'superstatic';
import * as path from 'path';
async function startStaticServer() {
const server = new Server({
port: 8080,
host: '127.0.0.1',
cwd: process.cwd(), // Serve from current directory by default
config: {
public: 'public', // Serve 'public' directory relative to CWD
cleanUrls: true,
rewrites: [{ source: '**', destination: '/index.html' }], // SPA rewrite
headers: [
{
source: '**/*.@(jpg|jpeg|gif|png|svg)',
headers: [{ key: 'Cache-Control', value: 'max-age=3600' }]
}
]
}
});
const app = server.listen(() => {
console.log(`Superstatic server running on http://127.0.0.1:8080`);
});
// Optional: Handle process exit for graceful shutdown
process.on('SIGINT', () => {
console.log('Shutting down server...');
app.close(() => {
console.log('Server gracefully shut down.');
process.exit(0);
});
});
}
startStaticServer().catch(console.error);