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:
- Install dotenvx
- Create your account (optional)
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(`ANTHROPIC_API_KEY: ${process.env.ANTHROPIC_API_KEY}`)