BeginnerCoder

Lesson 8 — Env config

Settings with safe defaults

Servers read settings like the port from environment variables — values set outside the code. In Node they live in process.env (for example process.env.PORT). If a setting is missing, use a default with ?? ("if null or undefined, use this instead").

const timeout = env.TIMEOUT ?? 5000;

Note: this playground runs JavaScript in your browser, not in real Node, so Node-only tools (like fs or http) are not available. The exercise is a small plain-JS simulation of the Node idea. Here env is a plain object standing in for process.env.

Why it matters: the same code runs on your laptop and in production, just with different settings.

Want it another way?
Task

Read PORT and HOST from env with defaults 3000 and "localhost", so it logs the address.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.