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-express

v3.0.0

Published

JavaScript bridge to enable the usage of Elm in the backend through Express

Readme

elm-express

elm-express

elm-express is a library that enables the use of Elm in the backend with Express. It is designed to provide minimal functionality and allow developers to use Elm and Express in a way that makes the most sense for their project.

The library consists of two parts: the Elm library and a JavaScript bridge. For instructions on using the Elm library, please refer to the documentation here.

This README file contains documentation for the JavaScript bridge.

Creating an elm-express application

If you want to write Elm in the backend and have already created your application using the elm-express Elm library, you'll need to wire up the JavaScript side. Here's how to install the bridge:

Installing the bridge

To install the elm-express JavaScript bridge, run the following command in your application's root directory:

npm install elm-express

Create your entry point

Next, create your entry point (index.js or server.js) by requiring the elm-express package and initializing your Elm application using Elm.Main.init():

const { elmExpress } = require("elm-express");
const { Elm } = require("./main");

const port = 3000;
const secret = "p4ssw0rd";
const app = Elm.Main.init();

const sessionConfig = {
  resave: false,
  saveUninitialized: true,
};

const server = elmExpress({
  app,
  secret,
  port,
  sessionConfig,
  requestCallback,
});

server.start(() => {
  console.log(`Example app listening on port ${port}`);
});

In this example, elm-express is initialized with an app instance, a secret key for signed cookies and session, a port number, a session configuration object, and a requestCallback function. You can define your requestCallback function to modify incoming requests before they are handled by your Elm application.

Note that the app instance is just a regular Elm application, so you can call ports and manipulate it as you would with any normal Elm application.

Also, elm-express does not have any opinions on how you should build or bundle your Elm application, so you can use any process you feel comfortable with to compile your Elm code.

Use your server instance

Finally, you can use your server instance as you would with any regular Express application. You can define routes, apply middleware, and more.

When you're ready to start listening for requests, call server.start(), which will automatically set up everything needed for your Elm application to properly handle requests and send responses.

Parameters

Here is a list of parameters that you can pass to the elmExpress function to create your application:

  • app: A reference to your initialized Elm application.
  • secret: A random string to be used by the cookie parser and session management libraries.
  • sessionConfig: An object with the necessary keys for session configuration. Check the Express documentation for more information on what can be configured here. Note that whatever secret you pass in this configuration object will be overwritten by the top-level secret to ensure consistency.
  • requestCallback: A callback function that will be called for every request. Check the /example folder for an example of how to use this callback.
  • errorCallback: A function that will be called with a string describing any internal errors. If not provided, the console.error function will be used to log the error message.
  • timeout: The maximum time (in milliseconds) a request can take before it is terminated. The default value is 5000.
  • port: The port to which the server should bind. The default value is 3000.
  • mountingRoute: The route at which the Elm application should be mounted. The default value is /.

How it works?

When server.start() is called in elm-express, a route is set up using server.all() and the specified mountingRoute. If the mountingRoute is /, the call will be server.all("/*"). This means that any sub-path will be caught by elm-express and passed to your Elm application for handling. There is no built-in router in elm-express, but you can use pattern matching to construct your model using information from the request, such as the URL and method, similar to how you would build a client-side SPA.

Example

The /example folder in the elm-express repository provides a comprehensive example of how to use the library's features. It includes examples of how to use Elm and JavaScript together to build a functional application. You can refer to this example to get a better understanding of how to use the library and its capabilities.