# .env Files — Node.js

Source: https://www.geekswithgeeks.com/en/nodejs/node-dotenv

> Keep secrets and per-environment config out of your code.

## A .env file

Store key=value pairs in a `.env` file, load them with the `dotenv` package (or Node's built-in `--env-file` flag).

```env
# .env
PORT=4000
DB_URL=postgres://localhost:5432/app
API_KEY=sk_test_123
```

## Loading it

Node 20+ can read a `.env` file natively — no package required.

```bash
node --env-file=.env server.js
```

## Never commit it

Add `.env` to `.gitignore` — commit a `.env.example` with placeholder keys instead.
