简体   繁体   English

相应地修改NODE_ENV

[英]Modify NODE_ENV accordingly

I'm rewriting a project from scratch using best practices and better config variables. 我正在使用最佳实践和更好的配置变量从头开始重写项目。 The idea is to have at least 3 environments: 这个想法是至少有3个环境:

  • development = hosted locally (on machine) 开发 =本地托管(在计算机上)
  • acceptance = hosted on personal NAS 接受 =托管在个人NAS上
  • production = hosted on rented server 生产 =托管在租用的服务器上

After some research I came across the following answer (on how to set NODE_ENV): 9198310 经过一番研究,我遇到了以下答案(关于如何设置NODE_ENV): 9198310

Doesn't this mean I have to change the environment manually before each code push? 这不是意味着我必须在每次输入代码之前手动更改环境吗? Is there a way to do this automatically by checking IP or DNS? 有没有办法通过检查IP或DNS来自动执行此操作?

FYI, I'm using docker to host the website on acceptance & production. 仅供参考,我正在使用Docker托管有关验收和生产的网站。 Not locally. 不在本地。

You can export NODE_ENV for each environment (can be added on profile.d on OS level) and then just start your nodejs app which will read that env. 您可以为每个环境导出NODE_ENV (可以在OS级别的profile.d中添加),然后仅启动您的nodejs应用程序,它将读取该环境。 variable. 变量。

"scripts": {
    "start": "node ./app"
  }

When run docker, you can set env. 运行docker时,可以设置env。 variable using: 变量使用:

 -e NODE_ENV='staging

Also you can take a look at pm2 manager. 您也可以看看pm2管理器。

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

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