Serving Static Files
LiteNode automatically serves files from a designated static directory with intelligent caching, file watching, and content-type detection.
Configuration
Default Directory
const app = new LiteNode()
// Serves ./static at /static/*
Files in ./static are accessible at http://localhost:5000/static/path/to/file.
Custom Directory
const app = new LiteNode("public")
// Serves ./public at /public/*
Disable Static Serving
const app = new LiteNode("__NO_STATIC_DIR__")
File Watching
The static directory is monitored at runtime. No server restart is needed for:
- New files — automatically registered and served
- Deleted files — routes removed
- Modified files — cache cleared
Caching
Development Mode
When NODE_ENV is anything other than "production", LiteNode uses ETag-based validation caching:
- Files are cached in memory for speed
- Changes are visible on a normal browser refresh (no hard refresh needed)
- Responds with
304 Not Modifiedwhen the file hasn't changed
Production Mode
When NODE_ENV=production:
- Static assets (images, styles, scripts) are cached for 24 hours
- Other content uses ETag validation
- Memory caching is disabled for better memory management
Set the environment with a .env file or your process manager:
NODE_ENV=production
Supported File Types
Browser-renderable:
- Images:
.avif,.gif,.ico,.jpeg,.jpg,.png,.svg,.webp - Styles:
.css - Scripts:
.js,.mjs - Documents:
.html,.txt,.pdf - Data:
.json,.xml - Media:
.wav,.mp3,.mp4,.webm,.ogg
Download:
- Archives:
.zip
Error Messages
# Static directory not found
[StaticAssetLoader] Error while reading static directory: "static" directory doesn't exist!
LiteNode will continue running without serving static assets.
# File serving error
[StaticAssetLoader] Error serving file {path}: {error message}
Cross-Platform Paths
Path normalization is handled automatically for Windows and Unix paths, mixed separators, and nested directory structures up to 10 levels deep.