node package manager


Node Elm Loader

A simple way to interoperate between Elm and NodeJS. Useful for sharing code between display and model logic, which holding it together with the rich Node ecosystem, for example, building your client-side components and minifying them with the rest of your assets!


You will need to already have the Elm platform installed on your system. Please find the relevant instructions here and a NodeJS development environment for v0.10.x.

Then, simply add elm-loader as a dependency in your package.json or run npm -g elm-loader.


First, write a simple module in Elm and expose a port! Due to a current bug in the compiler, you need to supply a dummy main function. Once this is resolved, it will be possible to proceed without the boilerplate.

module TickingPort where
import Signal
import Signal ((<~), Signal)
import Time
import Text
import Graphics.Element (Element)
main : Element
main = Text.asText "main"
port messageOut : Signal String
port messageOut = toString (Time.every Time.second)

Next, wire import your module into Node!

var path = require("path");
var Elm = require("elm-loader");
var compiledCode = Elm(path.resolve(__dirname, "ticking_port.elm"), __dirname);
compiledCode.emitter.on("messageOut", function(message) {

Watch it tick!

$ node test.js

You can also access the ports property, rather than the emitter on the object returned by the top level factory function and subscribe as you would with a typical setup.


The loader supports conventional CamelCase filenames for the Elm modules they contain. If you prefer to split thw words in your filenames with underscores, they will automatically be inflected to infer the module they contain, e.g. ticking_port.elm will correspond to the TickingPort module above.

If you are defining ports into Elm, you also need to supply a second argument to the factory function to define the defaults for those functions, e.g.

var echoPort = Elm(path.resolve(__dirname, "fixtures/echo_port.elm"), "fixtures", {
  messageIn: ""


To try it out, clone this repository, run npm link and then run node example/test.js!