2

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?

Ayush
  • 709
  • 2
  • 8
  • 17
  • It certainly depends on the context, and what you are trying to accomplish. In general, setting your configs in a file (such as config.json), and putting that file in your .gitignore, is a way to avoid exposing things like private API keys to anybody looking at your repo. With process.env, it's just going to be right out there in the code. Can you be more specific about the circumstance? – Christopher Ronning Aug 26 '16 at 21:14

2 Answers2

5

You generally use envvar to keep an application stateless. 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 ...

Config file are used for variables which are not dependent of the environment. For instance, name of the application, number of items per page ...

eli-bd
  • 1,533
  • 2
  • 17
  • 35
Sylwit
  • 1,497
  • 1
  • 11
  • 20
-1

I guess you can use config.json file for storing big configs. ENV I've usually use for passing application port or something very important for normal application start. For example if you use some external lib, it's better to be able to pass custom path to lib executor in ENV. P.S. You should never save config.json in SVN.