Backend Development
Step 6 / 2060 min

Environment & Config

Node.js Runtime

Explanation

Keep secrets out of git. Load PORT, DATABASE_URL, and AUTH_SECRET from environment variables.

Code example

typescript
const port = Number(process.env.PORT ?? 4000);
const databaseUrl = process.env.DATABASE_URL;
if (!databaseUrl) throw new Error("DATABASE_URL is required");

Helpful resources

Exercise

Add a .env.example file and fail startup if DATABASE_URL or AUTH_SECRET is missing.