I want to use a synchronous function asynchronously. So, I use fs.reddir function.
there is 'CSS' file in '../data'
this is my test.js file
var readdir_ = function (id) {
return new Promise(function (resolve, reject) {
fs.readFile (`../data/${id}`,'utf8',function(err, description) {
if (err) reject(err);
else {
resolve(description);
}
})
})
}
async function testB(id) {
await readdir_(id);
}
var id = 'CSS';
var _test= testB(id);
console.log(_test);
When I run the code above, the result is 'Promise { pending }'
but I want to get description
If you know how to get the 'resolve value', please let me know.
I really want to solve this problem.