i have a code in which i am creating a new directory. But the problem is that callback will call earlier while the directory will created. This method is inside the class. How to await until the file will be created and then call callback? I need something async/await, but i don't know how to wrap it. any solutions ?
createMissingPath(newFilePathname, callback) {
try {
let currentIndex = 0;
while ((currentIndex = newFilePathname.indexOf('/'/*path.sep*/, currentIndex+1))!= -1) {
let lastPath = newFilePathname.substr(0, currentIndex);
if(!fs.existsSync(lastPath)) {
logger.info('Trying to create directory: %s', lastPath);
fs.mkdir(lastPath);
}
}
callback(null, null);
}
catch (exception) {
logger.error('Caught exception : %s', inspect(exception));
callback(exception, null);
}
}