To check if an environment variable is set in Node.js, we use the in
operator.
For instance, we write
if ("DEBUG" in process.env) {
console.log(process.env.DEBUG);
} else {
console.log("Env var IS NOT SET");
}
to check if the DEBUG
property is in process.env
with "DEBUG" in process.env
to check if the DEBUG
environment variable is set.