I have a code to read files' paths from a directory, and return them. i use async/await to call the function to do this, but i got Promise pending not the target value.
function readdirAsync(path) {
return new Promise((resolve, reject) => {
fs.readdir(path, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
}).then(res => {
const versions = res.map(filename => match(/^[\d]+(\.+\d+)+/g, filename)[0]);
return versions;
});
}
async function getVersions() {
const final = await readdirAsync(require('path').join('src/versions/'));
return final;
}
const versionsList = getVersions().then(res => res);
console.log(versionsList);