First of all I have checked all the questions on Stack Overflow regarding this.
I am trying to export variable str
whose value is getting updated inside the function to another module but it is showing undefined
after exporting it in another file.
But if I update the value of variable outside function then export is working fine.
I have a function with code in file Excel.js
var str='abc';
wb.xlsx.readFile(filePath).then(function()
{
var sh = wb.getWorksheet("Sheet1");
console.log("YOUR LECTURE IS",sh.getRow(goingSlot+1).getCell(DAY+1).value);
//console works fine
str="YOUR LECTURE IS"+sh.getRow(goingSlot+1).getCell(DAY+1).value;
//the assignment here leads to undefined after exporting
}
str="something";
//this successfully exports the value as something
And then I export this to my main file with syntax
exports.str=str;
Incase you need to see code for main file
The code for the main file is
const express=require('express');
const app=express();
const myle=require('./readingExcel.js');
const res=myle.name;
console.log(res);
//CONSOLE SHOWS UNDEFINED