SkillByAIOpen interactive version →

Lesson 20 / 30

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.

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.

PORT=4000 NODE_ENV=production node server.js

# or
export NODE_ENV=production
node server.js