[英]What is process.env.UNIVERSAL in this node.js code
I'm working through a react with node tutorial and i have some code that looks like this: 我正在通过节点教程的反应,我有一些看起来像这样的代码:
if(process.env.UNIVERSAL){
markup = ReactDOMServer.renderToString(...)
.
.
.
}
I understand that process.env stores environment variables but i'm not sure what UNIVERSAL
is or where it comes from. 我知道process.env存储环境变量,但我不确定
UNIVERSAL
是什么或它来自哪里。 I tried to print it out in this code: 我试着在这段代码中打印出来:
const port = process.env.PORT || 3000;
const env = process.env.NODE_ENV || 'production';
server.listen(port, err => {
if (err) {
return console.error(err);
}
console.info(process.env.UNIVERSAL + ' test');
console.info(`Server running on http://localhost:${port} [${env}]`);
});
But it comes out undefined. 但它未定义。 Any idea what
process.env.UNIVERSAL
is? 知道什么
process.env.UNIVERSAL
是什么?
While running a node.js code, you can specify the environment variables. 运行node.js代码时,可以指定环境变量。 Say for example you have your node.js server in
app.js
file. 比如说你在
app.js
文件中有你的node.js服务器。 You can specify the env parameters while running like 您可以在运行时指定env参数
NODE_ENV=development node app.js
for a UNIX
environment 对于
UNIX
环境
or 要么
SET NODE_ENV=development & node app.js
for Windows environment
适用于
Windows environment
and then you can access it in your scripts with process.env.NODE_ENV
然后您可以使用
process.env.NODE_ENV
在脚本中访问它
Similarly you can specify the environment UNIVERSAL
while running the script 同样,您可以在运行脚本时指定环境
UNIVERSAL
like 喜欢
UNIVERSAL=test node app.js
Since you are not specifying anything, you get its value is undefined
in the script 由于您没有指定任何内容,因此在脚本中
undefined
其值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.