# @ledgerhq/live-env

> Ledger Live environment definition

Latest version **4.0.0** (published 2026-09-11) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @ledgerhq/live-env
pnpm add @ledgerhq/live-env
yarn add @ledgerhq/live-env
bun add @ledgerhq/live-env
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2026-09-11 |
| First published | 2023-03-22 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 90.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 613 |
| Maintainers | phenry-ledger, sergii-shkolin, gbrahm-ledger, ldg-github-ci, vbouzon, ledger-releaser |
| Keywords | Ledger |

## Links

- npm: https://www.npmjs.com/package/@ledgerhq/live-env
- Repository: https://github.com/LedgerHQ/ledger-live
- Homepage: https://github.com/LedgerHQ/ledger-live/tree/develop/libs/env
- Issues: https://github.com/LedgerHQ/ledger-live/issues
- npm.io page: https://npm.io/package/@ledgerhq/live-env

## Recent versions

- 4.0.0 (latest) — 2026-09-11
- 4.0.0-nightly.20260911020507 (nightly) — 2026-09-11
- 2.10.0-next.0 (next) — 2025-06-09
- 2.4.1-next-new-cdn.0 (next-new-cdn) — 2024-11-13
- 2.4.1-ios-build-number.0 (ios-build-number) — 2024-11-07
- 2.4.1-fix-build-number-pre.0 (fix-build-number-pre) — 2024-11-07
- 2.4.1-ios-build-number-fix.0 (ios-build-number-fix) — 2024-11-07
- 2.4.1-spl-tokens-test.0 (spl-tokens-test) — 2024-11-04
- 2.4.1-spl-test.0 (spl-test) — 2024-10-29
- 2.1.0-windows-certificate.0 (windows-certificate) — 2024-05-28
- 1.0.1-hotfix.0 (hotfix) — 2024-02-21
- 1.0.0-new-wc.0 (new-wc) — 2024-02-20
- 1.0.0-new-wc-test.0 (new-wc-test) — 2024-02-20
- 1.0.0-wc-test.0 (wc-test) — 2024-02-14
- 0.9.0-custom-exchange.0 (custom-exchange) — 2024-01-09
- … 430 more at https://npm.io/package/@ledgerhq/live-env/versions

## README

# live-env

> [!WARNING]
> **Status: DEPRECATED** — `@ledgerhq/live-env` is being sunset. Do not add env var definitions and
> do not add call sites. To take an existing one out, read **[MIGRATION.md](./MIGRATION.md)**:
> every variable exits as a feature flag, an inline constant, `process.env` at the point of use,
> or a parameter the caller passes in.
>
> The package still works exactly as documented below until the last call site is gone.

`@ledgerhq/live-env` is the **framework** for typed runtime environment variables, enabling interoperability across `@ledgerhq/*` libraries. It exposes a reactive API (`getEnv`, `setEnv`, `changes`) but ships **no env-var definitions** — those live in the workspace-private `@shared/env` layer inside the monorepo.

## What it does

- Provides `getEnv(key)` / `setEnv(key, value)` for safe, typed access
- Emits a reactive stream (`changes`) when a value changes, enabling subscriptions
- Supports parsing from raw strings (e.g. `process.env`) with int/float/bool/JSON parsers
- Enforces initialization: every API throws until `injectDefinitions()` has been called

## Key exports / concepts

- `injectDefinitions(defs)` — must be called **once** before any other API, with a record of `EnvDef` entries
- `getEnv(name)` — read the current value of an env key
- `setEnv(name, value)` — override a value at runtime
- `setEnvUnsafe(name, rawString)` — parse and set from a raw string (e.g. `process.env`)
- `changes` — observable of `{ name, value, oldValue }` for reactive env updates

## Usage inside the ledger-live monorepo

Internal packages import from `@shared/env`, which calls `injectDefinitions()` at module load and re-exports a fully typed API. You do not need to call `injectDefinitions()` yourself.

```ts
import { getEnv, setEnv, changes } from "@shared/env";

const timeout = getEnv("GET_CALLS_TIMEOUT"); // number
const swapUrl = getEnv("SWAP_API_BASE"); // string
changes.subscribe(({ name, value }) => console.log(name, value));
```

## Usage outside the ledger-live monorepo

External consumers must supply their own definitions and call `injectDefinitions()` before any `getEnv`/`setEnv` call. The API will throw if called before initialization.

```ts
import {
  injectDefinitions,
  getEnv,
  setEnv,
  changes,
  intParser,
  boolParser,
  stringParser,
} from "@ledgerhq/live-env";

// 1. Define your env vars
const myDefinitions = {
  MY_TIMEOUT: {
    def: 30_000,
    parser: intParser,
    desc: "Request timeout in ms",
  },
  MY_DEBUG: {
    def: false,
    parser: boolParser,
    desc: "Enable debug logging",
  },
  MY_API_URL: {
    def: "https://api.example.com",
    parser: stringParser,
    desc: "Base API URL",
  },
} as const;

// 2. Inject once at app startup, before any imports that call getEnv
injectDefinitions(myDefinitions);

// 3. Use the API
const timeout = getEnv("MY_TIMEOUT"); // any at framework level — wrap it to type it
setEnv("MY_DEBUG", true);
changes.subscribe(({ name, value }) => console.log(`${name} changed to`, value));
```

> [!IMPORTANT]
> `injectDefinitions()` must be called **before** any module that calls `getEnv` or `setEnv` is evaluated. Place it at the very top of your application entry point, before other imports that may trigger env reads.

---
_Source: https://npm.io/package/@ledgerhq/live-env · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
