If you run EJS on the server, I’d simply validate the file names before putting them into the template. If it’s in the browser, check the emitted error event.
thanks for your reply.
maybe it looks like I know what I’m doing with all this fancy code , but I’m a novice at best. I really don’t know what i’m doing here. What you are suggesting is actually what I was trying to do with this part :
//check for icon
var fs = require('fs');
var arrayLength = arr.length;
for (var i = 0; i < arrayLength; i++) {
var imgfile = arr[i].country
if (fs.exists('./public/images/flags/' + imgfile + ".png") == true) {
//console.log('/public/images/flags/' + imgfile + ".png");
console.log('fs exists');
} else {
console.log('Not Found!');
}
}
When I run this code in console It just returns “Not Found” for every single row, I think I have messed up with the directory, but the file should be located in var/myproject/public/images/flags
Thanks for your help and letting me think for myself rather then just provide an quick answer. However this is actually really hard when one does not know any better
based on your suggestions I thought for sure this would work , but still no luck
if (fs.exists('../public/images/flags/' + imgfile + ".png") == true) {