smol

Package Version Hex Docs

A tiny web server for Gleam targeting all JavaScript runtimes (Node.js, Deno, Bun, and others).

Features

Installation

gleam add smol@2 gleam_javascript@1 gleam_http@4

Hello, World!

import gleam/javascript/promise
import smol

pub fn main() {
  let handler = fn(request) {
    smol.send_string("Hello, Joe!")
  }
  
  smol.new(handler)
  |> smol.start()
}

Runtime Adaptation

smol provides functions to adapt your Gleam handlers to different environments:

// Convert handler to standard Web Fetch API
let fetch_handler = smol.adapt(my_handler)

Cloudflare Workers

Cloudflare workers use the standard Web Fetch API, so smol applications run there by exporting a Worker fetch function and adapting the incoming request with smol.adapt.

//// ./src/server.gleam
import smol

pub fn fetch(request, env, ctx) {
  let fetch_handler = smol.adapt(handler(_, env, ctx))
  fetch_handler(request)
}

fn handler(_request, _env, _ctx) {
  smol.send_string("Hello, Joe!")
}
//// ./index.mjs
export * as default from "./build/dev/javascript/server/server.mjs";

Configure Wrangler to point at Gleam’s generated JavaScript module:

{
  "main": "./index.mjs",
  "compatibility_flags": [
    "nodejs_compat"
  ],
  "compatibility_date": "2026-05-29"
}

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

Search Document