Clients

Node.js client

The Node.js client is what your application uses to get its secrets: it loads a vault and hands your code the secrets you ask for.

Moving an app off a .env file, step by step: Get your Node.js secrets out of .env.

Install it

Requires Node.js 20 or later.

npm install @valt0/client

Open a vault

A vault is opened by its id; the name is a label you choose.

openVault loads a vault from the local service. Pass it the id that valt0 info prints for the vault. The service can only open a vault that has been imported into it. A vault you create is imported for you; for one made somewhere else, run valt0 import first.

It throws if the service cannot be reached or the vault cannot be loaded.

TypeScript
import { openVault } from '@valt0/client'

const vault = await openVault({
    id: 'your-vault-id',
    name: 'your-vault-name',
})

From CommonJS it is the same call, loaded with require:

CommonJS
const { openVault } = require('@valt0/client')

Read a secret

Ask for a secret by name, use it, then destroy it.

vault.secret(name) fetches one secret and resolves to a Secret. Take the value out as bytes where you can: bytes() hands back a copy you can wipe once you are done with it, and destroy() zeroes the secret's own buffer.

If you need the secret as a string use reveal().

TypeScript
const secret = await vault.secret('DATABASE_PASSWORD')

// Preferred: raw bytes you can wipe when done
const bytes = secret.bytes()

// Or, when a string is unavoidable
await db.connect({ password: secret.reveal() })

// Zero the underlying buffer as soon as you are finished
secret.destroy()

Unless you ask for its value, a Secret prints as [REDACTED]: in a log line, a template string, JSON and a stack trace alike. The value comes out only through reveal() or bytes().

TypeScript
console.log(secret)             // Secret([REDACTED])
console.log(`${secret}`)        // [REDACTED]
JSON.stringify({ pw: secret })  // {"pw":"[REDACTED]"}

secret.reveal()                 // the actual value

API

openVault(options): Promise<Vault>

Opens the vault identified by id. Throws if the service cannot be reached or the vault cannot be loaded.

Options

idstring
The vault's id, the one valt0 info prints. It is the only value used to find the vault.
namestring
A label for the vault, used in messages.

Vault

The opened vault object.

Fields

id
The vault's id.
name
The vault's name.

Methods

secret(name)Promise<Secret>
Fetches one secret by name.

Secret

An object representing a vault secret.

Methods

bytes()
A copy of the raw bytes. Preferable to use, if possible, because a copy can be wiped.
reveal()string
The value decoded as UTF-8 text.
destroy()
Remove the secret from memory.