0

I am new to nodejs and java script.

I am trying to read a config.json file in nodejs project using the below code snippet.whenever i run the program it's giving an error 'TypeError: Cannot set property 'getProjectSettings' of undefined'

Can some one help me to find the issue with the code?

var Env = "DEV"

function getConfigValue(configKey, subConfigKey, isblnEnvattr, callback) {

    return callback(configKey, subConfigKey, isblnEnvattr);

}

function readConfigJson(configKey, subConfigKey, isblnEnvattr) {

    if (Boolean(isblnEnvattr) == true) { //eg MONGODB_DEV
        configKey = configKey + "_" + Env;
    }

    try {
        return 'x';
    } catch (err) {
        return "key Not found";
    }
}

module.export.getProjectSettings = function (configKey, subConfigKey, isblnEnvattr) {
    return getConfigValue(configKey, subConfigKey, isblnEnvattr, readConfigJson)
}

getProjectSettings("Primary","secondary",false)

1 Answer 1

4

You have a typo - it should be module.exports, not module.export.

module.exports.getProjectSettings = function (configKey, subConfigKey, isblnEnvattr) {
    return getConfigValue(configKey, subConfigKey, isblnEnvattr, readConfigJson)
}

Also, you can skip module before export, as long as you are not trying to export only one function (like such exports = function () { ... }).

exports.getProjectSettings = function (...) { ... } 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.