I'm trying to read all the files inside a specific folder.
But I'm having some issues returning an array with all those files' data.
My function is returning an empty array because the return is called before all values have been pushed into the array.
How can I fix this problem using asynchronous mechanisms?
app.get('/load-schemas', async function (req, res) {
var schemas = [];
fs.readdirSync('Schemas').forEach(file => {
fs.readFile('Schemas/' + file, "utf8", function(err, data) {
schemas.push(data);
})
});
res.status(200).send(schemas);
})