Skip to content

Custom Getter #313

Description

@A-312

We should allow to set custom getter to add more choice between env, arg and .load(.

Example: Custom Getter for file

const schema = {
  db: {
    name: {
      doc: 'Database name',
      format: String,
      default: 'users',
      getter: 'file',
      filepath: '/mycustompath/togetmy/name'
    }
  }
}

// convict.addGetter(name, priority, getter)
convict.addGetter('file', 70, (name, val, schema) => readFile(schema.filepath))

Custom priority level

And we should allow to set custom priority level : https://github.com/mozilla/node-convict/blob/master/lib/convict.js#L600-L601

Priority level Getter
0 Default value
20 File or json set in function argument
40 Environment variables (only used when env property is set in schema)
60 Command line arguments (only used when arg property is set in schema)

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