This project demonstrates how to use elm-pages 3.0 with Express.js.
You can see it in action at https://elm-pages-v3-express.fly.dev/.
See the discussion on elm-pages adapters at dillonkearns/elm-pages#378.
adapters/express/adapter.mjs
runs at build time and integrates the elm-pages renderer and Express middleware intodist-server/
.- After running
npm run build
, the adapter will generate:dist-server/server.mjs
: A Node.js Express server configured for elm-pages. Run directly withnode dist-server/server.mjs
or vianpm start
.dist-server/middleware.mjs
: Exports a default function for serving the elm-pages app via Express middleware. Place this middleware after any routes you don't want handled by elm-pages.
- Clone the repo and run
npm install
. - Ensure Lamdera is installed (see below).
- Use
npm run dev
to start the development server with hot reloading. - Use
npm run build
to build the app for production. - Use
npm start
to start the production server.
This example is deployed to Fly.io, but it can run on any platform that supports Node.js.
Deploy your own with these instructions.
Note: The default Dockerfile
generated by flyctl may need adjustments for elm-tooling and Lamdera. You can use the Dockerfile in this repo as a reference.
elm-pages
3.0 uses the Lamdera compiler, a superset of the Elm compiler with added functionality to automatically serialize Elm types to Bytes.
Lamdera may occasionally give compiler errors due to corrupted dependency cache. If you see the message:
-- PROBLEM BUILDING DEPENDENCIES ---------------
...
Note: Sometimes `lamdera reset` can fix this problem by rebuilding caches, so
give that a try first.
Use lamdera reset
to clear the caches. More information is available in the Lamdera docs: Lamdera Documentation.
Check out the Package Docs. You can also use npx elm-pages docs
from your project to view documentation for the RouteBuilder
module.
- Install dependencies with
npm install
. - Run a script with
npx elm-pages run script/src/AddRoute.elm User.Id_
ornpx elm-pages run script/src/AddStaticRoute.elm HelloWorld
. You can also use a shorter command likenpx elm-pages run AddRoute User.Id_
.
I aim to keep elm-pages-starter-express minimal and flexible, providing a straightforward foundation for various projects. I’m always open to PRs that improve the project while maintaining this simplicity. Feel free to contribute enhancements or fixes that align with this philosophy, and thank you for helping make the project better!