0

I'm using fs.readdir callback function to do stuff in a path file but i want to wait for the callback to be finished to continue on with the rest of my code.

const get = async(path_files) => {
    fs.readdir(path_files, function(err, files) {
        do stuff that takes time;
    })
};

When I call this function, I want the console.log to run after the callback of fs.readdir (which is not the case with this code).


const start_get = async() => {
    await get(path_files);
    console.log("the stuff was done");

}

I've seen similars answers on the website but I can't wrap my head around it.

RouckyKM
  • 85
  • 1
  • 8

0 Answers0