1. Read an env var
process.env exposes environment variables as strings; PORT is a common one for config.
process.env.PORTTyporithm · medium
Step 1 of 8 · intro card
HTTP & Events
process is the global handle on the running Node program: process.env reads config strings, process.argv holds command-line arguments, process.on("SIGINT") catches Ctrl+C for graceful shutdown, and process.exit(code) ends the program with an exit code.
process.env is a map of environment variables — always strings — used for configuration like process.env.PORT; missing keys are undefined.
process.argv is the array of command-line arguments: index 0 is the node binary, index 1 the script, and index 2 onward are user arguments.
process.on("SIGINT", ...) intercepts Ctrl+C so you can close connections before process.exit(code) ends the program — a non-zero code signals failure.
process.env.PORT reads config as a string.
process.argv[2] is the first user CLI argument.
process.on("SIGINT") enables graceful shutdown before process.exit.
const port = process.env.PORT
const flag = process.argv[2]
process.on("SIGINT", () => {
process.exit(1)
})Connect each part of the code to the concept before you type.
process.env exposes environment variables as strings; PORT is a common one for config.
process.env.PORTprocess.argv holds command-line arguments; index 2 is the first user-supplied argument.
process.argv[2]process.on("SIGINT") catches Ctrl+C so you can clean up before the process ends.
process.on("SIGINT", () => {process.exit(1) ends the process with a non-zero code signalling an error.
process.exit(1)Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.