Elm Beyond the Browser: Type-Safe Scripting with elm-pages by Tomas Latal

December 9, 2025

Tomas Latal showed that Elm isn’t just for the browser: with elm-pages v3 and elm-pages run, you can write type-safe CLI scripts in Elm. Using BackendTask, he demonstrated how to parse command-line options, read environment variables (like a GitHub token), call the GitHub API, read usernames from a local file, and either print results to the terminal or write them as markdown files. He also showed you can bundle the script into a Node .mjs file to run without elm-pages. The takeaway: Elm’s purity, composability, and compiler guidance work great for scripting—especially when you can reuse existing Elm decoders and domain code.

Elm is usually introduced as a “front-end language” — a pure functional language that compiles to JavaScript and is famous for friendly compiler errors and “no runtime exceptions” as a design goal. In his talk “Elm Beyond the Browser: Type-Safe Scripting with elm-pages”, Tomas Latal showed a less-known side of the ecosystem: you can use Elm to write CLI scripts — the kind you’d normally reach for Bash or Node.js for — while keeping the same type-safety and composability Elm developers love.

 

The key idea: elm-pages run as a scripting platform

Tomas’ core message was that elm-pages (v3) isn’t just a static site generator anymore. With its BackendTask system — and specifically elm-pages run — you can write scripts that:

  • parse command-line arguments
  • read environment variables (e.g., API tokens)
  • call external HTTP APIs
  • read files from disk
  • write output files (including streaming to disk)
  • optionally bundle the script to run directly in Node

The same Elm strengths apply: immutable data, explicit error handling, and compiler guidance when you inevitably make a mistake during development.

 

Live demo: from “Hello world” to a GitHub data pipeline

The presentation was a live demo delivered from a terminal-based slide tool (because, of course). Tomas built the script step-by-step:

 

Step 1: Console output

A minimal script printed “Hello Func Prog Sweden 2025” using an Elm Script task, proving the basic workflow: write Elm → run in terminal.

 

Step 2: Command-line options

Next, he added CLI parsing via elm-pages’ program configuration. The script accepted a –username option and printed a personalized greeting. A nice bonus: defining options automatically generated a –help output, so you don’t need to hand-roll usage text.

 

Step 3: Calling the GitHub API with an environment token

He then introduced HTTP calls and environment variables. Since GitHub’s API rate limits are tight without authentication, the script read a token from the environment—using a strict “expect” style getter that fails fast if the variable is missing.

This step also showcased an important BackendTask concept: tasks can fail in different ways (fatal vs recoverable), and the compiler will force you to handle those cases. Tomas intentionally leaned into this by using helper functions that “fail loudly” when appropriate—his recurring theme: “fail gloriously”.

 

Step 4: Reading local files and composing many tasks

The script evolved to accept a –file argument pointing to a text file containing GitHub usernames (one per line). The script then:

  • read the file as a string
  • split it into lines
  • filtered out empty lines
  • fetched user + repo data for each username
  • combined many backend tasks into a single composed task

This was the most “FP-feeling” part of the demo: the pipeline was built from small composable steps, and Elm’s types made the flow hard to misuse.

 

Step 5: Writing results to files (and streaming output)

Finally, Tomas added an output mode to write markdown files per user instead of printing to the console. Using BackendTask.Stream, the script wrote files like:

  • user-info/<username>.md

This turns the script into a practical data-prep tool: fetch data → format it → store it for later analysis, reporting, or further automation.

 

Bonus: Bundle the script and run it in Node

A particularly useful closing tip: you can bundle the Elm script into a runnable .mjs file, then execute it directly with Node. That makes it easier to integrate into CI pipelines or environments where you don’t want to install elm-pages as a runtime dependency.

 

Why this matters

The broader takeaway wasn’t “use Elm for everything.” It was more pragmatic:

  • If you already have Elm code (decoders, domain types, formatting helpers),
  • and you need scripts to process APIs/files in a safe, repeatable way,
  • then Elm + elm-pages gives you a surprisingly powerful, type-safe scripting workflow.

It’s also a compelling example of how functional programming shines outside traditional “application development”: composable pipelines, explicit effects, and compiler-driven correctness are just as valuable in one-off scripts as they are in production systems.

 

Q&A highlights

In the discussion, Tomas noted that elm-pages uses a wire protocol approach (via Lamdera under the hood for certain parts) to make server↔client data exchange efficient, and recommended checking elm-pages documentation — especially the section on when it’s not a good fit. He also shared that he uses elm-pages in side projects and JAMstack-style workflows, sometimes pairing it with a headless CMS so non-technical users can update content while builds regenerate static output.

 

Additional resources

Check out more from the MeetUp Func Prog Sweden. Func Prog Sweden is the community for anyone interested in functional programming. At the MeetUps the community explore different functional languages like Erlang, Elixir, Haskell, Scala, Clojure, OCaml, F# and more.