Node.js
/Intermediate
process.env
Definition
A property of the global `process` object containing the user environment. It is the standard way to pass secret configuration (like API keys) to a Node.js app.
Explain Like I'm New
You NEVER hardcode your database passwords or Stripe API keys in your code, because if you upload it to GitHub, hackers will steal them. Instead, you put secrets inside a hidden `.env` file on your computer. When Node runs, it reads that file and injects the secrets into `process.env`.
Real World Example
Connecting to a database: `mongoose.connect(process.env.DATABASE_URL)`.
Common Use Cases
- •Storing secrets safely
- •Switching between Development, Staging, and Production databases dynamically
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- What popular NPM package is used to load a `.env` file into `process.env`?
intermediate
- What is `process.env.NODE_ENV` conventionally used for?
advanced
- Should you ever commit a `.env` file to a public git repository?