Node.js · Junior · Question 47 of 75

How do you read an environment variable PORT?

Explanation

Values in process.env are always strings (or undefined), so convert them: Number(process.env.PORT ?? 3000).

Further reading

Problem with a question

Node.js · Junior · question 47

Test yourself

Take the Node.js · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz