LiteNode's logo

LiteNode

Docs GitHub logo
▶ Usage

Documentation

Serving Static Files

LiteNode introduces a static asset loader feature, allowing developers to serve static files effortlessly. This feature provides seamless integration for serving CSS, JavaScript, and images.

Nota bene: The static directory is monitored for changes, and newly added files are automatically registered and served. This ensures that any changes to the static assets are immediately reflected and accessible without the need for server restarts!

Default Directory

LiteNode serves static files from the static directory by default:

const app = new LiteNode()

app.startServer()

This will serve files from the static directory.
Accessing http://localhost:5000/path/to/file will serve the corresponding file from the static directory.

The static directory should exist at the root of your application, otherwise the following message will appear:

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

Custom Directory

LiteNode can serve static files from a specified directory:

const app = new LiteNode("public")

app.startServer()

This will serve files from the public directory.
Accessing http://localhost:5000/path/to/file will serve the corresponding file from the public directory.

The public directory should exist at the root of your application, otherwise the following message will appear:

Error while reading static directory: "public" directory doesn't exist!
LiteNode will continue running without serving static assets.

NO STATIC DIRECTORY

To use LiteNode without a static asset folder and avoid warning messages, set the directory to __NO_STATIC_DIR__:

const app = new LiteNode("__NO_STATIC_DIR__")

This will skip serving static assets and avoid logging warnings to the console.


Supported extensions

You can serve files with the following extensions from the static assets directory:

Content