Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/panosoft/elm-node-main
Node main for Server-side Elm programs
https://github.com/panosoft/elm-node-main
Last synced: 2 months ago
JSON representation
Node main for Server-side Elm programs
- Host: GitHub
- URL: https://github.com/panosoft/elm-node-main
- Owner: panosoft
- License: unlicense
- Created: 2016-09-12T21:14:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-28T14:40:04.000Z (almost 8 years ago)
- Last Synced: 2024-08-05T20:31:54.922Z (6 months ago)
- Language: Elm
- Size: 2.93 KB
- Stars: 24
- Watchers: 9
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Node main for Server-side Elm
> Node main for Server-side Elm programs
## Install
There's no installation necessary, this is a boilerplate file that can be used as the entry point for all Server-side or command line based Elm programs.
## Usage
Your final output of your Elm build must be called `elm.js`. This will be loaded via `require` in `main.js`:
```
elm make YourApp.elm --output elm.js
```Then your main Elm App should be a port module:
```elm
port module YourApp exposing (..)```
Then your Elm code can initiate a controlled shutdown by writing the exit code to a port called `node`:
```elm
port exitApp : Float -> Cmd msg
```When it's time to exit, your `update` function can do the following:
```elm
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
SomeEvent ->
(model, exitApp 1)
```
See `YourApp.elm` code for more usage details.## SIGINT and SIGTERM
These OS signals will send a message to your program. In the case of the test app, `YourApp.elm`, an `Abort` message is sent. Then the `exitApp` Cmd is returned from `update` with a parameter of -1 which will be returned to the OS.
This approach allows your Elm code to shutdown cleanly and allows you Elm code to always be in control.
## Exit Handlers
Besides the Elm exit handler, it also has a handler for Unhandled Exceptions which returns 1 to the OS. This is useful if you've written or used any badly behaved Javascript code.