A tiny web framework for Gleam targeting all JavaScript runtimes
12

Configure Feed

Select the types of activity you want to include in your feed.

Gleam 57.9%
JavaScript 35.8%
HTML 5.6%
Shell 0.1%
Other 0.7%
72 1 10

Clone this repository

https://tangled.org/becca.monster/smol https://tangled.org/did:plc:tkgzvfwj6z5zduays6cuwmvq
git@tangled.org:becca.monster/smol git@tangled.org:did:plc:tkgzvfwj6z5zduays6cuwmvq

For self-hosted knots, clone URLs may differ based on your setup.



README.md

smol#

Package Version Hex Docs

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

Features#

  • 🦄 Cross-Platform: Use it with Node.js, Deno, Bun or serverless functions with the same API
  • 🚀 Fully Featured: First-class support for chunked responses, Server-Sent Events and WebSockets
  • 🧩 Uses the platform: Built-in support for streaming files and working with JSON, uses standard Web APIs under the hood.

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.