Skip to content

Get Started

This guide walks through defining non-secret values in layeron.config.ts, choosing the active Layeron environment, and reading values from route code.

Put Env values in layeron.config.ts:

Terminal window
import { project } from "@layeron/core"
export default project({
app: "./src/app.ts",
env: {
defaults: {
API_BASE_URL: "https://api.example.com",
FEATURE_CHECKOUT: false,
REGION: "us-east",
},
prod: {
FEATURE_CHECKOUT: true,
RATE_LIMIT: 100,
},
dev: {
API_BASE_URL: "http://localhost:3000",
REGION: "local",
},
},
})

defaults apply to every environment. The active environment then overrides those values.

Run local development or deploy with the environment you want to resolve.

Terminal window
layer dev --env dev
layer deploy --env prod

For prod, the resolved Env values above are:

Terminal window
{
API_BASE_URL: "https://api.example.com",
FEATURE_CHECKOUT: true,
REGION: "us-east",
RATE_LIMIT: 100,
}

Read Env values from runtime code:

Terminal window
import { layeronEnv } from "@layeron/runtime"
app.get("/api/config", () => {
return {
apiBaseUrl: layeronEnv("API_BASE_URL").string(),
checkout: layeronEnv().boolean("FEATURE_CHECKOUT"),
region: layeronEnv().string("REGION"),
rateLimit: layeronEnv().number("RATE_LIMIT"),
}
})

env is also exported as a short alias:

Terminal window
import { env } from "@layeron/runtime"
const region = env("REGION").string()
  • Runtime values: Review available readers, supported value types, and the Env versus Secrets boundary.
  • Secrets: Use Secret references when runtime code needs sensitive values.
  • CLI environment variables: Review CLI environment variables that affect local and deploy commands.