[英]can'f find the “process.env.NODE_ENV”
The variable process.env.NODE_ENV
always bothers me every time I see it in a config file, especially webpack.config.js
. 每当我在配置文件中,尤其是webpack.config.js
看到变量process.env.NODE_ENV
总是感到困扰。 Where can I find this? 在哪里可以找到这个? Because sometimes I want to change it's value to production
instead of development
. 因为有时我想将其价值更改为production
而不是development
。
You can set any environmental variable like NODE_ENV
while running your applications. 您可以在运行应用程序时设置任何环境变量,例如NODE_ENV
。
Linux/Mac Linux的/苹果机
NODE_ENV=production node myapp.js
Windows/Powershell 在Windows / PowerShell的
$env:NODE_ENV="production" ; node myapp.js
You can access environmental variable NODE_ENV inside your myapp.js by 您可以通过以下方式访问myapp.js中的环境变量NODE_ENV:
process.env.NODE_ENV
process.env.NODE_ENV
is Node.js
environment. process.env.NODE_ENV
是Node.js
环境。
With the help of this mostly we decide our deployment environment in which we are deploying the code. 借助这一点,我们可以决定要在其中部署代码的部署环境。
It can be development
, stag
or production
. 它可以是development
, stag
或production
。
We can do other stuff on env
, it's up to us. 我们可以在env
上做其他事情,这取决于我们。
to set in Linux
在Linux
设置
export NODE_ENV=production 出口NODE_ENV =生产
on Windows
在Windows
set NODE_ENV=production 设置NODE_ENV =生产
Example 例
config.js
{development:{
//your `env` value
},
production:{
//Your `env` value
}}
Now on the basis of NODE_ENV
your env will be set 现在,根据NODE_ENV
您的环境将被设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.