Encrypt a .env file in Node.js
Encrypt a .env file in Node.js with the Dotenvx SDK, commit it safely, and load its secrets at runtime.
1. Install
Get the Dotenvx Node.js SDK.
$ npm install @dotenvx/dotenvx
# or
# bun add @dotenvx/dotenvx
# pnpm add @dotenvx/dotenvx
2. Encrypt
Encrypt your .env file.
$ npx dotenvx encrypt
◈ encrypted (.env)3. Inject
Then inject your encrypted secrets at runtime.
index.js
require('@dotenvx/dotenvx').config()
console.log(`HELLO: ${process.env.HELLO}`)