Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Javascript getters calling during config initialization #749

Open
bublig737 opened this issue Nov 16, 2023 · 0 comments
Open

[BUG] Javascript getters calling during config initialization #749

bublig737 opened this issue Nov 16, 2023 · 0 comments

Comments

@bublig737
Copy link

Describe the bug
// config/default.js

module.exports = {
    application: {
        name: process.env.NAME,
        get currentIp() {
            console.log('Getter called')
            return getCurrentIp()
        }
    }
}

function getCurrentIp() {
    return '123.123.123'
}

//index.js

console.log('Log BEFORE config import');

const config = require('config')

console.log('Log AFTER config import');

console.log('Current Ip', config.application.currentIp);

Logs output:
Log BEFORE config import
Getter called
Getter called
Getter called
Getter called
Getter called
Log AFTER config import
Getter called
Current Ip 123.123.123

Expected behavior

Expected to not calling getters during initialization of config, as in commonJs. For me its needed because I'm using
dynamic cashed values so getters need to be called only after some services will be inited.

Screenshots
image

image

Please tell us about your environment:

  • node-config version: 3.3.9
  • node-version: v16.17.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant