SpaceNode
The simplest way to use SpaceNode — serve a static website with HTML, CSS, JavaScript, and images. No modules, no controllers. Just files.
my-site/
├── app.js
├── package.json
└── public/
├── index.html
├── about.html
├── style.css
└── img/
└── logo.png
import { createApp } from 'spacenode'
const app = await createApp({
static: './public', // serve files from ./public
spa: false, // multi-page mode (each .html is its own page)
})
app.listen(3000, () => {
console.log('Site running on http://localhost:3000')
})
That's it. 3 lines of code and your site is live.
{
"type": "module",
"dependencies": {
"spacenode": "^1.0.0"
},
"scripts": {
"start": "node app.js"
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Site</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
<h1>Welcome!</h1>
<p>This is a static site served by SpaceNode.</p>
<img src="/img/logo.png" alt="Logo">
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>About — My Site</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
<h1>About Us</h1>
<p>A simple static page.</p>
</body>
</html>
| URL | File Served |
|---|---|
/ | public/index.html |
/about | public/about.html (clean URL) |
/about.html | public/about.html |
/style.css | public/style.css |
/img/logo.png | public/img/logo.png |
/about serves about.html automatically/../../../etc/passwd is blockednode app.jsspa: true (or just remove the option — it's the default). Then all unmatched routes fall back to index.html, perfect for React/Vue/Svelte apps.compress and security pipes: pipe: ['compress', 'security']. This adds gzip/brotli compression and security headers (HSTS, X-Frame-Options, etc.).