简体   繁体   English

如何在Node.js中检测我的环境?

[英]How to detect my environment in Node.js?

I am trying to deploy my app online and therefore I need to use different files depending on the environment. 我正在尝试在线部署我的应用程序,因此需要根据环境使用不同的文件。 However, I don't know how to detect which environment I am working in. 但是,我不知道如何检测我在哪个环境中工作。

Basically I am just looking for a variable which enables me to say if I am in development or in production to specify my static routes. 基本上,我只是在寻找一个变量,该变量使我能够说出我是在开发中还是在生产中以指定我的静态路由。 How can I do this? 我怎样才能做到这一点?

Well this isn't a complete answer, but process.env is the Node.js portal to the environment variables used to start the app. 好吧,这不是一个完整的答案,但是process.env是用于启动应用程序的环境变量的Node.js门户。
So, if you had your environment set via the NODE_ENV variable (which is a pseudo-standard for Node), you could do the following: 因此,如果通过NODE_ENV变量(Node的伪标准)设置了环境,则可以执行以下操作:

if (process.env.NODE_ENV === "production") {
  doProductionThings();
} else {
  doDevelopmentThings();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM