Skip to content

ref

Source: src/Railway/ref.ts

Emit a Railway variable-reference template (${{Service.KEY}} or ${{shared.NAME}}). Distinct from the unexported resource-prop Ref<T> — never export that Ref.

Railway.ref(Db, "DATABASE_URL") returns ${{LogicalName.DATABASE_URL}} where LogicalName is resource.LogicalId (Postgres("Db")Db). Shared variables use the "shared" namespace: Railway.ref("shared", "SENTRY_DSN") returns ${{shared.SENTRY_DSN}}.

Store the string as a Variable value (or on Service.env). Railway keeps the template (unrendered: true) and interpolates it at build/runtime — it is not a resolved URI. Use ConnectPostgres when you want a typed client inside an Effect-native Service.

Railway interpolates by service name. Set name on Postgres/Service to the LogicalId if you need the template to resolve to that service.

Pass a resource (or its LogicalId) and the variable key. The result is a template string, not a URI.

const db = yield* Railway.Postgres("Db", { project: site });
yield* Railway.Variable("DatabaseUrl", {
project: site,
service: api,
name: "DATABASE_URL",
value: Railway.ref(db, "DATABASE_URL"),
});

"shared" is the environment-wide namespace (IaC ctx.shared.NAME).

env: {
SENTRY_DSN: Railway.ref("shared", "SENTRY_DSN"),
}