In my file functions.js i have two functions:
var email, url1
function getFile(_callback){
email = fs.readFileSync("C:/Emails/" + items[2])
_callback(email);
}
function getUrl(){
getLatestMail(function(email) {
email.split(/\n/).forEach(function(line) {
i++;
if (i == 52) {
var test = new Buffer(line, 'base64').toString();
var regex = /=(.+?)"/g
var result1 = regex.exec(test);
url1 = result1[1].toString();
console.log(url1);
}
});
getUrl()
exports.resetUrl = url1;
And i have a file test.js
var Functions = require('../pageobjects/functions.js');
var test = Functions.resetUrl;
console.log(test);
But it returns always undefined! The console.log in getUrl() shows the good value. It looks like that the export not is waiting until the function getURl is loaded. What is the best way to solve this? In this example i removed all the unnecessary code parts.