Coder Social home page Coder Social logo

Comments (6)

twitchard avatar twitchard commented on May 19, 2024 3

Gah I'm so sorry. I was writing a description, but then thought better of my idea halfway through writing it. Didn't realize the issue had been created.

What it was: I was a little surprised to see

Error: 'foo.enable_debug' reuses an env variable: ENABLE_DEBUG.

when I tried to do

var config = convict({
    foo: {
        enable_debug: {
            doc: "Enable debug for the foo service",
            format: Boolean,
            default: true,
            env: "ENABLE_DEBUG"
        }
    },
    bar: {
        enable_debug: {
            doc: "Enable debug for the bar service",
            format: Boolean,
            default: true,
            env: "ENABLE_DEBUG"
        }
    },
})

What I initially expected was for this to be accepted, and both foo.enable_debug and bar.enable_debug to be set to the value of process.env.ENABLE_DEBUG if it was set. In a sense, that seems more natural. (And for my use case, more convenient.) But after thinking about it, I see the merits of enforcing one setting per env variable. Somebody might be surprised if you changed one environment variable and this affected multiple settings.

Anyway, if you are not opposed to the behavior I have described, I would gladly add a pull request. If not, it would probably be a good thing to document in the README.md. (only one setting allowed per env variable)

from node-convict.

madarche avatar madarche commented on May 19, 2024 1

Fixed by #189

from node-convict.

vladikoff avatar vladikoff commented on May 19, 2024

what does this mean?

from node-convict.

jcollum avatar jcollum commented on May 19, 2024

Any movement on this? I think env variable reuse should be an overridable flag.

from node-convict.

madarche avatar madarche commented on May 19, 2024

@twitchard I didn't know about this behavior: sure at least this should be documented in the README and should also be unit tested (I haven't found any test about this behavior - just a quick search).

@twitchard @jcollum I'm personaly not against and opt-in making it possible to reuse env variables. A PR on this could be accepted if the code is clean, doesn't add to the complexity of Convict, and with a matching unit test. At the moment the only time we pass options is in the validate method. So, to be accepted, a PR should provide a nice/easy/intuitive way to pass this option. So should we move this env variable reuse enforcement/check only in the validate method? Please elaborate on this point. Thanks

from node-convict.

madarche avatar madarche commented on May 19, 2024

You might be interested by new options available for the validate method that has just landed https://github.com/mozilla/node-convict#configvalidateoptions with #182 as it seems a good place to deal with options. I'm not saying it's the way to go, just that this is a possible choice. Cheers.

from node-convict.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.