Answer the question
In order to leave comments, you need to log in
What is the best config file type to use for Node.js?
There are three options:
1)
File: " .env ";
Usage: " process.env.key
";
View: " key=value
"
Features: Minimalistic file
2)
File: " config/default.json "
Usage: " "
View: " "
Features: Structural flexibility file 3)
File: " config.js "
Usage: " "
View: " "
Features : No modules required, even more flexible, easy to useconfig.get('key')
{"key": "value"}
config.key
export default {key: 'value'}
Personally, for now, I like the last option, because. does not require extra dependencies, and a different language context (js-js, instead of: js-json or js-raw), but I'm interested in other potential nuances in other options, what are they, if any?
Answer the question
In order to leave comments, you need to log in
1) the main feature is that when working correctly, the parameters are taken not only from this file, but also from real environment variables. This allows you to have different settings in different environments (one locally, others on the product server, and third on Vasya's). Plus, different things like passwords and keys are not stored in the source code, but are stored where this code will be executed.
2) Format understood by all. It is convenient if your configs are processed or generated somewhere else besides the node
3) it is convenient because you can stuff some logic there.
take 3 + 1
everything that may depend on the runtime environment - in .env, everything else - in js - config where you read it all and put it together
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question