# process.env — Node.js Fundamentals: Modules, Async and Servers

Source: https://www.skillbyai.com/en/nodejs/node-process-env

> Configure apps per environment with process.env, safe defaults and inline environment variables.

## Reading variables

`process.env` exposes environment variables as strings — always provide a fallback.

```javascript
const port = process.env.PORT || 3000;
const env = process.env.NODE_ENV || "development";

console.log(`Starting in ${env} mode on port ${port}`);
```

## Setting them

Set variables inline before the command, or export them for the session.

```bash
PORT=4000 NODE_ENV=production node server.js

# or
export NODE_ENV=production
node server.js
```
