Deviopath › Node.js

Port from Environment

Easy · Environment

Servers usually read their port from process.env.PORT. Environment values are always strings (or missing).

Write a function getPort(env) that returns the port as a number. Return the default 3000 when PORT:

- is missing

- is not made of digits only (so "80abc" and "3.5" are invalid)

- is outside 1-65535

Next: Allowed Methods