Can I run Elm with/on Nodejs

3,927 views
Skip to first unread message

robkuz

unread,
Jan 9, 2015, 8:45:22 AM1/9/15
to elm-d...@googlegroups.com
I havent found anything to declare the contrary but also nothing that says its possible.
And if it is possible can I import JS libs into the ELM Repl? or how is that done?

Thanks for clarification

Rob

Aaron VonderHaar

unread,
Jan 9, 2015, 11:16:23 AM1/9/15
to elm-d...@googlegroups.com
The closest I know of to what you seem to want is here:
https://github.com/maxsnew/IO

The elm-io.sh script there takes a .js file generated by elm-make, and
adds a few things to it to make it work nicely with nodejs. There's
not really any support for using external node libs, but you could
possibly get something working with some combination of custom
modifications to the elm-io.sh script and doing some node-specific
stuff in native elm modules.

In summary, I believe there's nothing officially supported to do this,
but a few people are starting to experiment with it.
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elm-discuss...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
--Aaron V.
[ http://github.com/avh4 ]

Sonny Michaud

unread,
Jan 9, 2015, 11:24:53 AM1/9/15
to elm-d...@googlegroups.com
I wrote a NPM module that goes in the opposite direction - allowing you to import Elm code into your JS: https://www.npmjs.com/package/elm-loader

- Sonny

Joey Eremondi

unread,
Jan 9, 2015, 11:59:11 AM1/9/15
to elm-d...@googlegroups.com
@robcuz the important thing to remember is that Elm is just a way to translate elm code into JavaScript.

So really, you can run Elm with any platform that interacts with JS, because the result of elm-make is JavaScript. So you use the code Elm generates as part of a JS project. Ports makes this particularly elegant.

Here's the tutorial on Ports:
http://elm-lang.org/learn/Ports.elm

As for importing libs into elm-repl, that's not possible because it would violate purity. It's easy to call Elm from JavaScript, but calling JavaScript from Elm is tough, because there's no guarantee that JS code is pure (performs no side-effects) or typesafe. So your best bet is to choose the functionality you want to import and set up ports for them.

Sonny Michaud

unread,
Jan 9, 2015, 12:09:11 PM1/9/15
to elm-d...@googlegroups.com
Everything Joey said is spot on.  I should have pointed out that my library simply takes care of running elm-compile for you and giving you access to the ports from your Elm code.  Basically, the point is to reduce the friction of those additional build steps for you.  There is also an interoperability layer between the ports from Elm and Node EventEmitter objects, so people familiar with the latter can concern themselves with the details less.

- Sonny

Tom F

unread,
Feb 24, 2017, 10:56:11 AM2/24/17
to Elm Discuss
Hey guys,

I'm also very interested in running elm server side (especially node.js), and would appreciate to hear about your experiences & tips.

Thx !

art yerkes

unread,
Feb 25, 2017, 1:29:58 PM2/25/17
to Elm Discuss
I've also been using elm on the server side, and have some thoughts:

In elm-0.18 you'll use a Platform.program or Platform.programWithFlags and pass command line arguments via the flags from a small javascript runner.  Unlike Sonny Michaud's approach, I've used the normal init/update/subscriptions approach and it can also work well.

The skeleton I made for elm on node is here:

You can use web side elm packages like Html (alongside elm-server-side-renderer) and elm-lang/http as well if you're willing to postprocess the elm output a small amount.
Reply all
Reply to author
Forward
0 new messages