0

I'm developing server side app on Node.js and I thinking about config file usage. But when I google it.. well as for now I have more questions then answers.

In my case I have a-lot-of functions with arguments different types of sensitivity not just only secret, tokens, keys. Most of this argument as user-depended. For example, user that launch app use to define (via CLI [promtly]): number of days, how much times something will execute, when and where, etc

For example I just check this question and that article. And my question is simple:

Which one to use and why? (or where can I read more about it) Using only .env file, or only config.json or probably both like in article above? Is it OK to store all settings in package.json or not? (like in this question)

I'd be very pleased if more experienced JS devs tell me what should I use and why.

Even if this question is marked as answered feel free to tell me (and everyone on SO) about your experience with such problem. But please, remember, that I'm asking not about *How to do it* or about DotEnv usage (or any other npm module). It's all about patterns & practices.

AlexZeDim
  • 3,520
  • 2
  • 28
  • 64
  • 1
    "What practice is better?" is opinionated and therefore off-topic. "Which to use when?" wouldn't be off-topic. – Jonas Wilms May 06 '19 at 16:21
  • It's fixed. Well as for me, I guess the the main reason why I asked this question, was about anti-patterns and use cases. I can put all necessary data/args in `.env` file but probably (for some reason that I don't know that) it's not `ok`. So maybe someone could explain me that. – AlexZeDim May 06 '19 at 16:26

1 Answers1

2

Is it OK to store all settings in package.json or not?

For sure you could theoretically do that. But you want to configure your service, and you usually run the same package with different configurations. Therefore it really makes sense to have some kind of configuration file, then you can set up different configurations for your local testserver, your development server, your production server and so on.

.env file or config.json ?

That is really up to you. However the .env file seem to not support any nested data, which I think is really useful for configuration. I always used config jsons, and that worked quite well so far.

In my case I have a-lot-of functions with arguments different types of sensitivity not just only secret, tokens, keys.

For sensitive data inside of a production environment you should really use a secret store (e.g. Vault). For local testing environments this is irrelevant though.

Most values are user-depended

Then either store them in a config file, or use a database.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
  • Thanks you for your answer. Well as I understand it, most relevant practice will be usage of `.env` and `config` file combined. Storing `args` in DB is not an option in my case. Actually, becuase I have only one `user` which is manage the whole system. So I don't need to store many variables of settings. – AlexZeDim May 06 '19 at 16:40