Packages

Static File Handling Package

A guide to static file handling in Raptor

Installation

To start using the static file handling, simply install into an existing Raptor application with your package manager.

deno add npm:@raptor-js/static
bun add @raptor-js/static
npm install @raptor-js/static
yarn add @raptor-js/static
pnpm add @raptor-js/static

Configuration

An optional configuration object is available, allowing you to customise your static file handling setup.

import type { Config } from "@raptor-js/static";
 
export default {
  /**
   * The directory to serve static files from.
   */
  directory: "/public",
} satisfies Config;

For more information about the config-driven setup, see Configuration.

Usage

The static handler supports a configurable path, relative to the current working directory.

import static from "@raptor-js/static";
import { Kernel } from "@raptor-js/kernel";
 
import config from "./static.config.ts";
 
const app = new Kernel();
 
app.use(static(config));
 
app.use(
  () => `
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="/css/style.css">
</head>
<body>
  <h1>It's a UNIX System! I know this!</h1>
</body>
</html>
`,
);
 
app.serve();

The code above will render an HTML page and load in the stylesheet with the correct headers.

© 2026 Raptor