Skip to content

Arguments precedence #50

Description

@jmendiara

I've experimented that the prefedence for args parsing is (from low to hight)
Default -> File -> environment args -> command line -> api

Default is overwritten by File, File by Environment args...

I.e, in this scenario

var convict = require('convict');

var conf = convict({
  ip: {
    doc: "The IP address to bind.",
    format: "ipaddress",
    default: "127.0.0.1",
    env: "IP_ADDRESS",
    arg: "ip"
  }
});
conf.loadFile('./config.json');

conf.set('ip', '134.234.32.56'); //or conf.load({ip:'134.234.32.56'});
conf.validate();

console.log(conf.get('ip'))

config.json

{
 "ip": "192.168.1.1"
}
$ IP_ADDRESS=10.95.78.123 node server.js --ip 0.0.0.0
# Output: 134.234.32.56
# Precedence: Default(127.0.0.1) -> File (192.168.1.1) -> Env(10.95.78.123) -> Arg(0.0.0.0) -> API (134.234.32.56)

Is this correct?
Maybe would you add this to the FAQ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions