I am using NodeJS for this. I have a configuration.js module which I use in index.js.
configuration.js
let spctrConfiguration = {
    dataPath: '/data/',
    mongoDB: 'datadb',
    mongoHost: 'mongo',
    mongoPort: 27017,
    redisHost: 'redis',
    redisPort: 6379,
    getLogPath: () => {
        console.log(this); //this is {}
        return path.join(this.dataPath, 'spctrworker_logs');
    },
    getHtmlPath: () => {
        return path.join(this.dataPath, 'spctrworker_html');
    }
};
if (process.env.SPCTR_MODE == 'DEVELOPMENT') {
    spctrConfiguration.dataPath = __dirname + '/dev_data/';
    spctrConfiguration.mongoHost = '127.0.0.1';
    spctrConfiguration.redisHost = '127.0.0.1';
}
module.exports = spctrConfiguration;
index.js
let spctrConfiguration = require('./config/configuration');
let app = express();
let logPath = spctrConfiguration.getLogPath();
let htmlPath = spctrConfiguration.getHtmlPath();
Of course this throws an error since this.dataPath is undefined.
My question is why is this an empty object.
What I am expecting is that this inside the getLogPath function refers to spctrConfiguration object. Since the function getLogPath was called from spctrConfiguration in index.js. Any help is much appreciated!
