Configuration
Listen ports, database credentials, and JWT secrets live in your app. Set them with Server and Repo helpers, the same way Ecto configures a repo.
App config
Start from Server.defaultConfig and Repo.postgres (or sqlite / ets), then pipe in the values you want. Decode process env (and optional .env via Env.load) into a type alias with Env.Decode: you either get a Config or an Err. Request body limits are Config fields too (maxBodySize, bodySpoolThreshold); raise them for Multipart file uploads. For HTTPS, set both tlsCert and tlsKey to PEM file paths (Cowboy start_tls); omit them for plain HTTP.
type alias Config =
{ host : String
, dbPort : Int
, user : String
, password : String
, dbName : String
, httpPort : Int
}
configDecoder : Decode.Decoder Config
configDecoder =
Decode.map6
(\host dbPort user password dbName httpPort ->
{ host = host
, dbPort = dbPort
, user = user
, password = password
, dbName = dbName
, httpPort = httpPort
}
)
(Decode.varOr "PGHOST" "127.0.0.1" Decode.string)
(Decode.varOr "PGPORT" 5432 Decode.int)
(Decode.varOr "PGUSER" "postgres" Decode.string)
(Decode.varOr "PGPASSWORD" "" Decode.string)
(Decode.varOr "PGDATABASE" "selm" Decode.string)
(Decode.varOr "PORT" 3000 Decode.int)
config : Config
config =
case Env.decode configDecoder of
Ok value ->
value
Err message ->
Debug.todo message
serverConfig =
Server.defaultConfig
|> Server.httpPort config.httpPort
|> Server.maxBodySize (32 * 1024 * 1024)
|> Server.bodySpoolThreshold (256 * 1024)
repo =
Repo.postgres
|> Repo.host config.host
|> Repo.dbPort config.dbPort
|> Repo.user config.user
|> Repo.password config.password
|> Repo.dbName config.dbName
|> Repo.poolSize 8
Use Decode.var when a key must be set (missing or bad values become Err). Use Decode.varOr when a local default is fine if the key is unset; a present but invalid value still fails. Use Decode.optional for Maybe values (unset → Nothing). JWT signing takes the secret as an argument, so each server in an app can use its own key:
Jwt.signWithExp mySecret (60 * 60 * 24) { userId = id }
Jwt.verify mySecret token
Confirm-address and magic-link tokens use the same idea via Email.verificationToken / Email.verifyToken (HS256, purpose email.verify). Build HTML bodies with Email.Mjml, then Email.htmlMessage / Email.message and Email.send over SMTP or an HTTP JSON webhook; pass the relay config in source like Repo.
Factory defaults (port 3000, local Postgres, empty password) are only a starting point in the runtime. Prefer setting the fields you rely on in source.
selm_pg accepts trust, cleartext, MD5, and SCRAM-SHA-256, whichever the server offers in pg_hba.conf. Local examples use trust on 127.0.0.1 with an empty Repo.password. For remote or password-auth databases, set Repo.password and prefer SCRAM over cleartext password auth. MD5 is only for older servers.
Distributed nodes
By default selm run and selm serve start an anonymous BEAM node. Pass iex-style flags (or env vars) to give the node a name and cookie so you can attach a console and talk to other nodes:
selm run --sname counter --cookie secret
selm run --name app@127.0.0.1 --cookie secret
SELM_NODE=counter SELM_COOKIE=secret selm serve
--sname starts a short name (-sname). --name starts a long name (-name); include @host when you care about the host part (for example app@127.0.0.1). There is no default cookie: pass --cookie, set SELM_COOKIE, or put [distribution] cookie in selm.toml. SELM_NODE / SELM_COOKIE work the same way when you omit the flags (SELM_NODE with @ is treated as a long name). Packaged releases read the cookie from SELM_COOKIE at start time (not from selm.toml).
Then selm console opens a Selm expression REPL on that node (attach if it is up, otherwise boot the app like iex -S mix; quitting a booted console stops that node). It reads build/dev/erlang/node.name from the last start, or you can pass --sname / --name again. Up/^P walk history (~/.selm_history, mode 600). Optional ~/.selm_console and <project>/.selm_console preload imports and bindings (--no-init skips the project file; --no-boot refuses to start the app). Stdlib Node connects peers; Erpc calls remote functions; Process.remoteSubject sends typed mailbox messages to a registered name on another node.
selm console --erl is the classic Erlang remsh shell. selm console --offline typechecks against the project without joining a node.
Build output
Build output uses fixed paths under build/; no env vars. After selm make, the BEAM runtime finds them relative to erlang/ebin:
build/dev/schema.sql
build/dev/models.json
build/dev/migrations/plans.json
build/client/app.js
build/client/app.hash
build/dev/erlang/node.name