LiteNode's logo

LiteNode

Docs GitHub logo
▶ Usage

Documentation

Serving Static Files

LiteNode includes a powerful static asset loader that automatically serves files from a designated directory. The loader includes intelligent caching, file watching, and automatic content-type detection.

Basic Configuration

Default Directory

By default, LiteNode serves static files from the static directory:

const app = new LiteNode()
app.startServer()

Files in the static directory will be accessible at:
http://localhost:5000/static/path/to/file.

Custom Directory

You can specify a custom directory for static files:

const app = new LiteNode("public")
app.startServer()

Disabling Static Assets

To run LiteNode without static asset serving:

const app = new LiteNode("__NO_STATIC_DIR__")

Caching and Performance Features

Development Mode

In development, LiteNode implements validation caching using ETags. To enable development mode, set NODE_ENV to anything other than "production" in your environment or .env file:

NODE_ENV=development

Development mode features:

Production Mode

When NODE_ENV is set to "production":

Automatic Content Type Detection

The loader includes:

Supported File Types

Browser-Renderable Files

Downloadable Files

File Watching and Auto-Updates

The static directory is monitored for:

Changes are handled automatically with no server restart required.

Error Handling

The loader provides consistent error handling with informative messages:

# Missing directory
[StaticAssetLoader] Error while reading static directory: "static" directory doesn't exist!
LiteNode will continue running without serving static assets.

# File serving errors
[StaticAssetLoader] Error serving file {path}: {error message}

# Directory scanning errors
[StaticAssetLoader] Error scanning directory {dir}: {error message}

Cross-Platform Compatibility

The loader handles path normalization automatically for:

Performance Optimizations

Content