I'm trying to get the login to work on a scheduler, but getting the module.exports.report.logon is not a function
error. This is the code:
const cron = require('node-cron');
const cms = require("g4js-cognos").Cms;
module.exports.report = new cms(url, namespace, usr, psw);
let task = cron.schedule('*/1 * * * *', function() {
logonToCognos();
}, true);
task.start();
function logonToCognos() {
module.exports.report.logon().then((response) => { // THE ERROR
console.log(" LOGGED on, status: " + response.statusCode);
}).catch((error) => {
console.log(" Logon on fail: " + error);
});
}
When I'm not using scheduller and module.exports.report
is outside of a function, everything works fine:
const cms = require("g4js-cognos").Cms;
module.exports.report = new cms(url, namespace, usr, psw);
module.exports.report.logon().then((response) => {
console.log(" LOGGED on, status: " + response.statusCode);
}).catch((error) => {
console.log(" Logon on fail: " + error);
});
Also, if I don't use module.exports, it is working fine (but I have to use exports because I need it in another module):
const cms = require("g4js-cognos").Cms;
const report = new cms(url, namespace, usr, psw);
let task = cron.schedule('*/1 * * * *', function() {
logonToCognos();
}, true);
task.start();
function logonToCognos() {
report.logon().then((response) => { // NO ERROR
console.log(" LOGGED on, status: " + response.statusCode);
}).catch((error) => {
console.log(" Logon on fail: " + error);
});
}
Any ideas? Why is module.exports working so different? Thanks.