I want to read all the JSON files from the data folder. I use the library https://www.npmjs.com/package/node-dir. I got a function, but it does not work synchronously. Variable replacements
renders undefined
.
async function giveHtml() {
let replacements = await dir.readFiles(__dirname + '/data', { match: /.json$/ }, (err, content, next) => {
if (err) {
throw err
}
next()
})
console.log(replacements)
return replacements
}
What's my mistake?