This is my file loginHandler.js
class LoginHandler {
merchantId = '';
returnURLForIframe(req, res) {
merchantId = req.params.merchantId;
}
}
module.exports = new LoginHandler();
I want to access the variable merchantId
on another file
const loginHandler = require('./loginHandler')
class ResponseHandler {
getResponseFromCOMM(options,token, res){
console.log(loginHandler.merchantId)
}
}
But merchantId is undefined. Can you please tell me what I am doing wrong?
Here you can see the code on Glitch = https://glitch.com/edit/#!/turquoise-spiky-chrysanthemum
I solved it by adding it to an environment variable on loginHandler.js
process.env.MERCHANT_ID = req.params.merchantId
and then on responseHandler.js, I accessed that variable
merchantId : process.env.MERCHANT_ID