I tryed to make simple script that create a folder if it not exsists. I readed some articles and maked logic like this:
debug("before async");
(async () => {
if(!fs.existsSync(outputPath)){
debug("Folder not exsists! path: "+outputPath)
try{
return await fs.mkdir(outputPath)
}catch(err){
debug(err)
}
}
res.send('<h1>Hello world!</h1>')
})()
I got an error:
(node:27611) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.
Ok. I figured a little and remind that guy from stackoverflow tell me make callback functon as promisify. I tryed to make it:
const mkdir = util.promisify(fs.mkdir);
debug("Before async");
(async () => {
if(!fs.existsSync(outputPath)){
debug("Folder not exsists! path: "+outputPath)
await Promise.all(mkdir(outputPath))
}
res.send('<h1>Hello world!</h1>')
})()
But I got other error:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: undefined is not a function
How was I supposed to make all? If you know any guides that can help me to understand about asynchronous functionality - that will be great. Thanks!
btw, both ways folder was created. but with errors...