smol
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.