I'm new to NodeJS+JavaScript. In the following JS the excelData returns a Promise when require from another JS. In the importing JS I can resolve and get it's value. But without exporting a promise, how to export the array directly?
I need this because I have a JS where promises are not supported.
var conf = require('../config');
var excel = require('exceljs');
var workbook = new excel.Workbook();
var excelData = workbook.xlsx.readFile(conf.intentExcel).then(function() {
var customerSheet = workbook.getWorksheet(conf.customerDataSheet);
var excelRows = [];
customerSheet.eachRow({
includeEmpty : true
}, function(row, rowNumber) {
if (JSON.stringify(row.values[1])) {
var rowObj = {
intent : JSON.stringify(row.values[1]),
level : JSON.stringify(row.values[2]),
optLvl1 : JSON.stringify(row.values[3]),
optLvl2 : JSON.stringify(row.values[4]),
optLvl3 : JSON.stringify(row.values[5]),
questionId : JSON.stringify(row.values[6]),
question : JSON.stringify(row.values[7]),
expAnswerId : JSON.stringify(row.values[8])
}
for ( var key in rowObj) {
if (rowObj[key] != null) {
rowObj[key] = rowObj[key].replace(/['"]+/g, '');
}
}
excelRows.push(rowObj);
}
});
return excelRows;
});
module.exports = {
excelData : excelData
};