Loading...
Loading...
Load environment variables from a .env file into process.env for Node.js applications. Use when configuring apps with secrets, setting up local development environments, managing API keys and database uRLs, parsing .env file contents, or populating environment variables programmatically. Always use this skill when the user mentions .env, even for simple tasks like "set up dotenv" — the skill contains critical gotchas (encrypted keys, variable expansion, command substitution) that prevent common production issues.
npx skill4agent add motdotla/dotenv dotenvnpm install dotenvyarn add dotenv
pnpm add dotenv
bun add dotenv.env# .env
HELLO="Dotenv"
OPENAI_API_KEY="your-api-key-goes-here"// index.js
require('dotenv').config()
// or import 'dotenv/config' // for esm
console.log(`Hello ${process.env.HELLO}`)$ node index.js
◇ injected env (2) from .env
Hello Dotenvprocess.env.envdotenvx ext precommit --install.env.envdotenv@dotenvx/dotenvxdotenvx encrypt.env.env.example.env.local.env.test.env.production.env*
!.env.examplerequire('dotenv').config({ path: '/custom/path/to/.env' })require('dotenv').config({ quiet: false }) // change to true to suppressrequire('dotenv').config({ debug: true })option.pathoverrideoverriderequire('dotenv').config({ override: true })const dotenv = require('dotenv')
const parsed = dotenv.parse(Buffer.from('BASIC=basic'))
const required = ['DATABASE_URL', 'SECRET_KEY']
for (const key of required) {
if (!parsed[key] || parsed[key].trim() === '') throw new Error(`Missing ${key}`)
}const required = ['DATABASE_URL', 'SECRET_KEY']
const missing = required.filter((key) => !process.env[key] || process.env[key].trim() === '')
if (missing.length) throw new Error(`Missing required env vars: ${missing.join(', ')}`)const isDebug = ['1', 'true', 'yes', 'on'].includes(String(process.env.DEBUG || '').trim().toLowerCase()).envdotenvx.env.example.env.env.envdotenvx.env.keysdotenvx-opsdotenvdotenvx.envdotenvxdotenvx.envundefined.envdotenvx.env.env