| title | Quickstart |
|---|---|
| description | Install the CLI, run barekey init, create a variable, and read it with the Barekey SDK. |
This quickstart uses the actual shipped workflow:
- Install and log into the CLI.
- Run
barekey init. - Create a variable.
- Read it with
@barekey/sdk/server.
- Node.js 18+ or Bun
- a Barekey account
Log in:
barekey loginCheck the session:
barekey whoamiIn your project root, run:
barekey initThis walks you through org, project, and stage selection and writes barekey.json for you.
The generated file looks like this:
{
"$schema": "./node_modules/@barekey/sdk/dist/barekey.schema.json",
"organization": "acme",
"project": "web",
"environment": "development",
"config": {
"mode": "centralized",
"typegen": "semantic",
"disallow_ambigious_keys": true
}
}Barekey also accepts the aliases org and stage, but the canonical keys are:
organizationprojectenvironment
Once this file exists, most CLI commands and SDK clients can resolve the target automatically.
Create a variable with an initial value:
barekey env new DATABASE_URL "postgres://localhost:5432/app" --type stringIf you omit arguments in an interactive terminal, Barekey can prompt you step by step instead.
Read it back:
barekey env get DATABASE_URLUpdate it later with env set:
barekey env set DATABASE_URL "postgres://localhost:5432/app_v2"Create a shared client:
import { BarekeyClient } from "@barekey/sdk/server";
export const barekey = new BarekeyClient();Because barekey.json is present, the client can resolve:
organizationprojectenvironment
And because you already logged in with the CLI, the SDK can reuse the local CLI session for auth during local development.
Read your variable:
import { barekey } from "./barekey";
const databaseUrl = await barekey.get("DATABASE_URL");
console.log(databaseUrl);If you want stronger startup guarantees, pass a schema directly:
import { z } from "zod";
import { BarekeyClient } from "@barekey/sdk/server";
const barekey = new BarekeyClient({
requirements: z.object({
DATABASE_URL: z.string().url(),
}),
});await barekey.get("DATABASE_URL") returns the parsed value for the variable's declared type.
If you want metadata too, use inspect():
const result = await barekey.get("DATABASE_URL").inspect();
console.log(result.value);
console.log(result.rawValue);
console.log(result.kind);
console.log(result.visibility);Run:
barekey typegenThis updates generated types inside your installed @barekey/sdk package so known keys become typed in your editor.
In development, you can keep it fresh:
barekey typegen --watchIf your local workflow still expects a dotenv file:
barekey env pull --out .env.localOr JSON:
barekey env pull --format json --out barekey.local.json