I am trying to read a file using the fs library then replace some elements after an iteration then return the composed string However, the function returns undefined
function concatproduce(order, producestring) {
if (order.cart.produce[0].productid != null) {
order.cart.produce.forEach((element, index) => {
if (!element.delstatus) {
element.delstatus = 'Pending';
}
fs.readFile('controllers/ordercartitemtemplate.html', 'utf8', function(err, data) {
if (err) {
return console.log('lima' + err);
}
//console.log(data)
producestring += (data
.replace('//Filename//', element.imageURL)
.replace('//Prodname//', element.producename)
.replace('//Quantity//', element.quantity)
.replace('//Price//', element.price)
.replace('//Total//', element.total)
.replace('//Delstatus//', element.delstatus));
});
});
return producestring;
}
}