Encrypt secrets in Node.js

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

Prerequisites

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

1. Install

Get the Dotenvx Node.js SDK.

npm install @dotenvx/dotenvx

2. Encrypt

Encrypt your .env file.

$ terminal

npx dotenvx encrypt

3. Inject

Then inject your encrypted secrets at runtime.

index.js

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

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