简体   繁体   English

NodeJS config.json与process.env进行配置管理

[英]NodeJS config.json vs process.env for configuartion management

I've come across people using both methods to do config management. 我遇到了使用这两种方法进行配置管理的人。

What are the pros and cons of each approach? 每种方法的优缺点是什么?

If I have a lot of variables that I store in my config object, will I have to set them all one by one in an upstart script before executing the node app? 如果我有很多变量存储在配置对象中,在执行节点应用程序之前,是否需要在新贵脚本中一一设置所有变量?

You generally use envvar to keep an application stateless. 通常,您使用envvar来使应用程序保持无状态。 The same codebase should work in dev, staging, test and production environment. 相同的代码库应在开发,登台,测试和生产环境中工作。 You will put var like MySQL config, API keys, if log is enabled or not, if debug is on or not ... 如果启用或未启用日志,是否启用调试,则将像MySQL配置,API密钥一样放置var ...

Config file are used for variables which are not dependent of the environment. 配置文件用于不依赖于环境的变量。 For instance, name of the application, number of items per page ... 例如,应用程序名称,每页项目数...

I guess you can use config.json file for storing big configs. 我想您可以使用config.json文件存储大型配置。 ENV I've usually use for passing application port or something very important for normal application start. ENV我通常用于传递应用程序端口或对正常启动应用程序非常重要的事情。 For example if you use some external lib, it's better to be able to pass custom path to lib executor in ENV. 例如,如果您使用一些外部库,则最好能够将自定义路径传递给ENV中的库执行器。 PS You should never save config.json in SVN. PS:永远不要将config.json保存在SVN中。

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

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