I'm new to node.js and I'm struggling with this problem. I don't understand why my output is
ciao
data
data
and not
data
data
ciao
This is my code
fs.readdir("sender", (err, files) => {
        if (err) {
            throw err;
        }
        const path = __dirname + "/sender/";
        let rawdata = fs.readFileSync(path + "data.json");
        var data = JSON.parse(rawdata);
        files.forEach((file) => {
            fs.stat(path + file, (err, stats) => {
                if (err) {
                    throw err;
                }
                if (data[file]["size"] != stats.size) data[file]["size"] = stats.size;
                if (data[file]["time"] != stats.mtime.toISOString()) data[file]["time"] = stats.mtime.toISOString();
                console.log("data");
            });
        });
        console.log("ciao");
    });
I've read that foreach is not asynchronous, so I don't really understand why the output is reversed.
 
    