elm-pages-starter-express

This is an example of using elm-pages v3 with Express. github , page

> The Adapter just copies the elm-pages renderer and a basic express server into dist-server and Node.js runs the server from there.

The idea of adapters is that they are responsible for turning the output of the elm-pages build into the right setup for a specific hosting provider. (i.e. adapting the output)

lamdera reset npm run build npm start

> start > node dist-server/server.mjs

On our server we get an error message: listen EADDRINUSE: address already in use. The reason is that our wiki server is configured to be available on port 3000. Therefore we have to use another port, e.g. 4040.

dist-server/server.mjs [⇒ Express]

import express from "express"; import elmPagesMiddleware from "./middleware.mjs"; const app = express(); const port = 4040; app.use(express.static("dist")); app.use(elmPagesMiddleware); app.listen(port, () => { console.log(`Listening on port ${port}`); });

$ npm start > start > node dist-server/server.mjs Listening on port 4040

elm-pages is running

Note: In case of 502 Bad Gateway, the server must be restarted ("npm start").

[~/.wiki/blog.dreyeck.ch/elm-pages-starter-express]$ npm start

~

What is the difference between .js and .mjs files? stackoverflow

> Node.js will treat .cjs files as CommonJS modules and .mjs files as ECMAScript modules. It will treat .js files as whatever the default module system for the project is (which is CommonJS unless package.json says "type": "module",).

In the most ubiquitous programming ecosystem, modules have been shoehorned in where they were originally lacking. As of early 2018, nodejs gradually builds toward ECMAScript Modules. Guidance for transition from CommonJS to ESM: link

What are ECMAScript Modules (ESM)? post

Vite serves source code over native ESM. page , Javascript Modules mdn