I have an array of names and would like to loop through each one of them and read a file corresponding to it with fs-extra which uses promises. How do i wait for the forEach loop to be over so i can write the results to json
Here's my current code:
const fs = require("fs-extra");
const path = require("path");
const manifest = require("../manifest.json");
manifest.forEach((element, index) => {
    const coinName = `${element.symbol.toLowerCase()}.svg`;
    let svgPath = path.join(__dirname, '..', 'svg', 'color', coinName);
    fs.readFile(svgPath, "utf8")
        .then(result => {
            const pattern = /#([A-Fa-f0-9]{6})/g
            let color = result.match(pattern)
            if (color === null) {
                manifest[index].color = undefined;
                console.log("null")
            } else {
                manifest[index].color = color;
            }
        })
        .catch(e => console.log(coinName + " NOT FOUND"))
});
fs.writeJSON("./manifest.json", manifest);
 
    