This quickstart uses the actual shipped workflow:
- Install and log into the CLI.
- Add a
barekey.json file.
- Create a variable.
- Read it with
@barekey/sdk/server.
Prerequisites
- Node.js 18+ or Bun
- a Barekey account
1. Install the CLI
npm install -g @barekey/cli
yarn global add @barekey/cli
Log in:
Check the session:
2. Add barekey.json
Create a barekey.json file in your project root:
{
"organization": "acme",
"project": "web",
"environment": "development"
}
Barekey also accepts the aliases org and stage, but the canonical keys are:
organization
project
environment
Once this file exists, most CLI commands and SDK clients can resolve the target automatically.
3. Create a variable
Create a variable with an initial value:
barekey env new DATABASE_URL "postgres://localhost:5432/app" --type string
Read it back:
barekey env get DATABASE_URL
Update it later with env set:
barekey env set DATABASE_URL "postgres://localhost:5432/app_v2"
4. Install the SDK
5. Read the variable in code
Create a shared client:
import { BarekeyClient } from "@barekey/sdk/server";
export const barekey = new BarekeyClient();
Because barekey.json is present, the client can resolve:
organization
project
environment
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);
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);
6. Generate SDK types
Run:
This updates generated types inside your installed @barekey/sdk package so known keys become typed in your editor.
In development, you can keep it fresh:
7. Optional: pull to .env.local
If your local workflow still expects a dotenv file:
barekey env pull --out .env.local
Or JSON:
barekey env pull --format json --out barekey.local.json
Pulled files contain plaintext values. Add them to .gitignore.
What next