Hi guys, I’ve been struggling in nodejs to add a logopath for my img files. I had a little breakthrough yesterday and was able to create this code (with help)
//check for icon
const fs = require('fs');
const path = require('path');
const imageDir = '/var/scraper/public/images/flags/';
var filesExist = arr.map((imgObj) => {
const imgfile = imgObj.country;
let filePath = path.join(imageDir, imgfile + ".png");
//console.log('Checking existance of file: ', filePath);
return { Logopath: fs.existsSync(filePath) ? filePath: path.join(imageDir, "noimage.png")};
});
and testing this in console like so:
console.log(filesExist);
This does indeed work as intended, However I need to add this data into my var arr
this var is created like so and have all the data I need
arr.push({
hteam: hteam,
ateam: ateam,
j: j,
statustype: $(this).attr('data-statustype'),
country: country,
league: league,
Kickoff: Kickoff
});
What I would like to do is to add another dimension to this arr var called Logopath with the data from the first function.
I have tried a few things but so far no luck.
Any Help at all would be much appreciated