Encrypt secrets in Bun

Learn how to encrypt your first .env file using Bun and the Dotenvx Node.js SDK.

Prerequisites

To get the most out of this guide, you'll need to:

1. Install

Install the Dotenvx Node.js SDK with Bun.

$ terminal

bun add @dotenvx/dotenvx

2. Encrypt

Encrypt your .env file.

$ terminal

npx dotenvx encrypt

3. Inject secrets

Then inject your encrypted secrets at runtime.

index.js

require('@dotenvx/dotenvx').config()

console.log(`HELLO: ${process.env.HELLO}`)