npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

elm-web-server

v5.0.0

Published

An API with Node.js-bindings for Elm WebSocket/HTTP-servers

Readme

Elm Web Server

An API with Node.js-bindings for Elm WebSocket/HTTP-servers.

Warnings

This package contains no native/kernel-code - All interop with Node.js is implemented using Elm's ports-API. Modules with ports are not intended for distribution on package-managers, as they can be unreliably implemented compared to regular Elm-modules, so open an issue if you encounter problems!

Elm, along with the Elm architecture, is designed for browser-applications; This project in an experimental attempt to embed the architecture inside Node.js.

Taking the unreasonable performance implications aside, it is fun to experience Elm as a shared language between client and server, with all of it's nice properties for refactoring and extension.

Features

  • A small API to hook Elm's Platform.program into Node/http and/or Websockets/ws in Node.js.
  • Modules for working with Http-Request/Response & WebSocket messages on the server.
  • Emulation for XmlHttpRequest & WebSocket to run elm-lang/http & elm-lang/websocket on the server.

Installation

The package is implemented using JavaScript language-features supported >= v6.13.1 of Node.js.

The package is distributed through NPM:

npm install -S elm-web-server

if you're going to use the Server.WebSocket-module, you will need to install the following package from NPM:

npm install -S ws

Open elm-package.json and expose the internal Elm-modules from the package like this:

{   
    ...
    "source-directories": [
        ...
        "node_modules/elm-web-server/source"
    ]
}

Take a look at the examples-directory for inspiration.

JavaScript Interface

in Node.js, assuming an Elm module named Main compiled to main.elm.js in the same directory, the API can be used as such:

const Ews = require("elm-web-server")
const Http = require("http")
const Ws = require("ws")
const App = require("./main.elm.js")

const PORT = process.env.PORT || 3000

const worker = App.Main.worker()

const server = Http.createServer(Ews.createRequestListener(worker))

Ews.attachMessageListener(worker, new Ws.Server({ server }))

Ews.attachConsoleListener(worker)

server.listen(PORT, () => {
    console.log(`listening at http://localhost:${PORT}`)
})

Importing elm-web-server automatically exposes XmlHttpRequest & WebSocket globally to enable server-side usage of elm-lang/http & elm-lang/websocket.

Elm Interface

There is a couple of small modules for Elm, written to facilitate some basic server-logic.

Server.Http

The HTTP-module exposes utility for working with HTTP-requests/responses.

type alias Request =
    { connection : Connection
    , method : Method
    , headers : List Header
    , url : Url
    , body : Maybe String
    }
type Error
    = ConnectionClosed Connection
    | Error String
listen : (Result Error Request -> msg) -> Sub msg
respondWith : (a -> String) -> Status -> List Header -> Maybe a -> Connection -> Response
respondWithJson : Status -> List Header -> Json.Encode.Value -> Connection -> Response
respondWithText : Status -> List Header -> String -> Connection -> Response
respondWithNothing : Status -> List Header -> Connection -> Response
send : Response -> Cmd msg
compareConnection : Connection -> Connection -> Bool

Server.Http.Url

The Http.Url module exposes types, decoding for Http-request urls.

toLocation is helpful if you want to parse urls using evancz/url-parser, as shown in examples/routing.

type alias Url =
    { pathname : String
    , search : String
    }
decoder : Decoder Url
toLocation :
    Url
    ->
        { href : String
        , host : String
        , hostname : String
        , protocol : String
        , origin : String
        , port_ : String
        , pathname : String
        , search : String
        , hash : String
        , username : String
        , password : String
        }

Server.Http.Method

The Http.Method module exposes types, encoding, and decoding for Http-request methods.

type Method
    = Get
    | Head
    | Post
    | Put
    | Delete
    | Trace
    | Options
    | Connect
    | Patch
    | Method String
encode : Method -> Json.Encode.Value
decoder : Decoder Method

Server.Http.Status

The Http.Status module exposes types, encoding, and decoding for Http-request statuses.

type Status
    = Ok
    | Created
    | Accepted
    | NonAuthoritativeInformation
    | NoContent
    | ResetContent
    | PartialContent
    | MultiStatus
    | AlreadyReported
    | ImUsed
    | MultipleChoices
    | MovedPermanently
    | Found
    | SeeOther
    | NotModified
    | UseProxy
    | SwitchProxy
    | TemporaryRedirect
    | PermanentRedirect
    | BadRequest
    | Unauthorized
    | PaymentRequired
    | Forbidden
    | NotFound
    | MethodNotAllowed
    | NotAcceptable
    | ProxyAuthenticationRequired
    | RequestTimeout
    | Conflict
    | Gone
    | LengthRequired
    | PreconditionFailed
    | PayloadTooLarge
    | URITooLong
    | UnsupporedMediaType
    | RangeNotSatisfiable
    | ExpectationFailed
    | ImATeapot
    | MisdirectedRequest
    | UnprocessableEntity
    | Locked
    | FailedDependency
    | UpgradeRequired
    | PreconditionRequired
    | TooManyRequests
    | RequestHeaderFieldsTooLarge
    | UnavailableForLegalReasons
    | InternalServerError
    | NotImplemented
    | BadGateway
    | ServiceUnavailable
    | GatewayTimeout
    | HTTPVersionNotSupported
    | VariantAlsoNegotiates
    | InsufficientStorage
    | LoopDetected
    | NotExtended
    | NetworkAuthenticationRequired
    | Status Int String
encode : Status -> Json.Encode.Value
decoder : Decoder Status

Server.Http.Header

The Http.Header module exposes types, encoding, and decoding for Http-request headers.

byteLength is helpful if you want to set the ContentLength-header, as shown in examples/routing.

type Header
    = ContentType MimeType
    | Accept (List MimeType)
    | ContentLength Int
    | Header String String
type MimeType
    = TextPlain
    | TextHtml
    | TextCss
    | ApplicationJson
    | ApplicationJavascript
    | MimeType String
encode : List Header -> Json.Encode.Value
decoder : Decoder (List Header)
byteLength : String -> Int

Server.WebSocket

The WebSocket-module exposes utility for working with WebSocket connections & messages.

type Message
    = Connected Connection
    | Disconnected Connection
    | Received Connection String
type Error
    = ConnectionClosed Connection
    | FailedToSend Connection String
    | Error String
listen : (Result Error Message -> msg) -> Sub msg
send : String -> Connection -> Cmd msg
disconnect : Connection -> Cmd msg
compareConnection : Connection -> Connection -> Bool

Server.Console

The Console-module allows you to print information to the console in different formats.

log : String -> Cmd msg
logError : String -> Cmd msg
logWarning : String -> Cmd msg