I'm using node 4.5+ and bluebird. I have the following code I intend to use with then
:
var checkdir = function(directory) {
return new Promise(function(resolve, reject) {
fs.statAsync(directory).then(function() {
resolve(true);
}).catch(function(err) {
if(err.code === 'ENOENT') {
fs.mkdirAsync(directory).then(function() {
resolve(true);
}).catch(function() {
reject(new Error('Can not create folder'));
});
} else {
reject(new Error('Unknown fs stat error: ' + err));
}
});
});
};
Async
functions are from fs-extra-promise
module. However, when I try to use this function, I get Unhandled rejection Error: Unknown error: TypeError: Cannot read property 'then' of undefined
.
Calling:
checkdir(dir).then(function() {
...
}).catch(function(err) {
reject(new Error('Unknown error: ' + err));
});
What is wrong here?