Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elm-node

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elm-node

Run Elm + JS programs easily in node

  • 1.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

elm-node

A Node.js CLI tool for easily running your elm code.

elm init
elm-node --example-elm > src/Main.elm
elm-node src/Main.elm

Warning: This isn't neither a beginner tool, nor the intended default Elm experience. If you want to experiment, use elm repl or elm-reactor. Using the elm CLI with --output=index.html is also a very easy way to try things. Really evaluate if you want or need node.js. You will need to be familiar and fluent in both node.js and Elm to make good use of this tool.

Usage

npm install -g elm-node, then make a directory to test it out.

mkdir my-node-project && cd my-node-project
elm init

See the following sections for usage instructions.

Simple setup, no JS

You can just create a Main.elm. On the JS side there will be a JS port called log that you can use to send String to output.

You can use --example-elm to get a very basic Main.elm to get started:

elm-node --example-elm > src/Main.elm
elm-node src/Main.elm
Running arbitrary JS

With the basic setup there is also a port eval subscribed to on the JS side that will run the code it receives. On the JS side there is also a global app variable that you can use in your JS code string to send events back to Elm. Not the most fancy way to interact with JS, but it gets the job done.

If you want to do something more complex see the custom setup below.

Custom JS setup

Similar to the previous setup, but you can provide a custom JS file that will get passed the Elm object so that you can init whatever app you want, or set up any ports you need.

The JS file passed, needs to export a function that will get the Elm object from the compiled output. You can do with it as you please.

You can use --example-elm and --example-js to get a very basic Main.elm and custom JS to get started:

elm-node --example-elm > src/Main.elm
elm-node --example-js > src/index.js
elm-node --js src/index.js src/Main.elm

Flags

You can pass --optimize for the compiler to do the optimized build, but it probably won't get you much in Node.js, except for getting rid of the development build warning output. The compile times are longer, so maybe just use it when you are going to ship.

Keywords

FAQs

Package last updated on 26 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc