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.
1. Define Env Values
Section titled “1. Define Env Values”Put Env values in layeron.config.ts:
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.
2. Select An Environment
Section titled “2. Select An Environment”Run local development or deploy with the environment you want to resolve.
layer dev --env devlayer deploy --env prodFor prod, the resolved Env values above are:
{ API_BASE_URL: "https://api.example.com", FEATURE_CHECKOUT: true, REGION: "us-east", RATE_LIMIT: 100,}3. Read Env Values
Section titled “3. Read Env Values”Read Env values from runtime code:
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:
import { env } from "@layeron/runtime"
const region = env("REGION").string()Next Steps
Section titled “Next Steps”- 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.