Bluebird Promise Is Undefined?
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) {
Solution 1:
Using any kind of "exists" check in filesystem operations is actively discouraged in the node documentation. (Whether you do the exists check with stat
or with exists
is irrelevant.)
That means, in addition to Benjamin Gruenbaum's comment regarding the improper use of promises in general in your code, there is another important point to make:
The right way to create a directory is by calling mkdir
unconditionally and ignoring EEXIST
(compare this answer for more context).
var fs = Promise.promisifyAll(fs);
var ensureDir = functionensureDir(path) {
return fs.mkdirAsync(path).catch((err) => { if (err.code !== 'EEXIST') throw err; });
}
You can use the mkdirp
module to create a path recursively, like mkdir -p
would.
Post a Comment for "Bluebird Promise Is Undefined?"