I was trying to solve one problem for sometime, and did research on stack-overflow but cant seem to be able to find any solution that would actually help me in achieving the result that I need to come to. I'm trying to assign an array of objects inside of an array, but instead of getting a value I get "Promise".
async function groupsCollections() {
mongo.connect(config.mongoURI, (err, client) => {
if (err) {
console.error(err)
return
}
const testFolder = './groupCollections';
let s = fs.readdirSync(testFolder)
let combine = [];
// going into each directory (Groups)
s.forEach(file => {
let tes = fs.readdirSync(`${testFolder}/${file}`)
let ad = tes.map(el => {
let see = readFileAsync(`${testFolder}/${file}/${el}`, { encoding: 'utf8' }).then((text) => {
let jsonFile = JSON.parse(text)
return jsonFile;
})
.catch((err) => {
console.log('ERROR:', err);
});
return see
})
combine.push({ groupName: file, collections: ad })
})
})
}
What should i change in my code, so that instead of Promises you would actually see values ? I was trying to solve this problem for hours but cant seem to find any other better solutions, so decided to come here and hope someone can guide me for the sake of a better solution to achieve the desired results.
Would really appreciate any assistance.