dotenv
Load environment variables from a `.env` file into `process.env` — the standard way to manage configuration in Node.js apps.
dotenv
Node.jsLoad environment variables from a `.env` file into `process.env` — the standard way to manage configuration in Node.js apps.
Fit
Bundle (gzip)
2.6 kB
5.8 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Hardcoding secrets (API keys, database URLs) in source code is a security risk. Managing different configurations for development, staging, and production environments requires a consistent, portable approach.
What It Does
dotenv reads a .env file in your project root and merges its KEY=VALUE pairs into process.env. It's a zero-dependency, 12-factor app pattern that separates config from code. The .env file stays out of version control while .env.example documents required variables.
Installation
npm install dotenvUsage Example
# .env
DATABASE_URL=postgresql://localhost:5432/myapp
JWT_SECRET=super-secret-key-here
STRIPE_KEY=sk_test_...// Must be the first import in your entry file
import 'dotenv/config';
// Or explicitly:
import dotenv from 'dotenv';
dotenv.config();
// Now access as normal
const db = new Database(process.env.DATABASE_URL!);Related packages
Role and attribute based access control (RBAC + ABAC) for Node.js with a fluent, readable API.
bcryptjsNode.jsPure JavaScript bcrypt password hashing — no native dependencies, same API as bcrypt, works anywhere Node.js runs.
bullmqNode.jsPremium message queue and job scheduler for Node.js backed by Redis — reliable background job processing with retries, priorities, and rate limiting.
casbinNode.jsA powerful authorization library that supports RBAC, ABAC, ACL and more via configurable policy models.
execaNode.jsProcess execution for Node.js — a better child_process with Promises, streaming, and a clean cross-platform API.