如何检查节点js中是否设置了环境变量?

时间:2022-06-09 22:51:28

I would to check if an environmental variable is set in my nodejs express server. In base of it is set or not, I would do different operations. I've tried this:

我想检查我的nodejs express服务器中是否设置了环境变量。在它设置或不设置的基础上,我会做不同的操作。我试过这个:

if(process.env.MYKEY !== 'undefined'){ console.log('It is set!'); }
else { console.log('No set!'); }

I'm testing without the process.env.MYKEY... but the console prints "It is set". Any help?

我正在测试没有process.env.MYKEY ......但是控制台打印出“It is set”。有帮助吗?

1 个解决方案

#1


16  

try this. i do this in my node.js project and it working fine.

尝试这个。我在我的node.js项目中这样做,它工作正常。

if(process.env.MYKEY) { 
    console.log('It is set!'); 
}
else { 
    console.log('No set!'); 
}

#1


16  

try this. i do this in my node.js project and it working fine.

尝试这个。我在我的node.js项目中这样做,它工作正常。

if(process.env.MYKEY) { 
    console.log('It is set!'); 
}
else { 
    console.log('No set!'); 
}