npm@envlet/sdk
Set up
Three steps. The host keeps one secret and everything else arrives at boot.
- 01
Install
One package. Node, Bun, and edge runtimes.
Terminalnpm install @envlet/sdk - 02
Set one secret
ENVLET_TOKEN on the host. It is the only secret the host keeps.
Node.js / production / environment variablesENVLET_TOKEN envlet_•••••••• the only secret the host keeps DATABASE_URL •••••••• moved to Envlet STRIPE_KEY •••••••• moved to Envlet SENTRY_DSN •••••••• moved to Envlet - 03
Inject at boot
Call inject() before anything reads process.env.
server.tsimport { inject } from "@envlet/sdk"; await inject(); const stripe = new Stripe(process.env.STRIPE_KEY);
Three calls
inject for most apps. load when you want a map. get when you want one value.
import { inject } from "@envlet/sdk";
await inject();
const stripe = new Stripe(process.env.STRIPE_KEY);Typed
envlet types writes this file from the variables in your environment, with a load() that fills the shape below. Run it with --check in CI and a renamed variable fails the build.
Terminal
envlet types
envlet types --checkenvlet.d.ts
// Generated by envlet types for the "production" environment.
import type { Env as EnvletEnv } from "@envlet/sdk";
declare module "@envlet/sdk" {
interface Env {
DATABASE_URL: string;
DEBUG: boolean;
FLAGS?: unknown;
MODE: "dev" | "prod";
PORT: number;
STRIPE_KEY: string;
}
}
type EnvletProcessEnv = { [Name in keyof EnvletEnv]: string };
declare global {
namespace NodeJS {
interface ProcessEnv extends EnvletProcessEnv {}
}
}
export {};Questions
Will my app start if Envlet is down?
No. The SDK retries for a few seconds, then fails so you notice. It never starts your app with half an environment.
What does the host need?
One variable, ENVLET_TOKEN. Everything else arrives at boot.
Can I still set some values on the Node.js host?
Yes. A value the host already set wins. Pass override if you want Envlet to win instead.