I use the bluebird magic
var fs = Promise.promisifyAll(require('fs'));
and use
fs.readdirAsync(dest).then(function (val) {
return val;
}).then(function (file) {
...
My question is for the following code (which is working) should I use the same and how
I am talking about the mkdir
function.
function createDir(folder) {
return function (req, res, next) {
if (typeof require.cache.per === 'undefined') {
require.cache.per = {};
require.cache.per.mk = false;
}
if (!require.cache.per.mk) {
fs.mkdir(folder, function (e) {
if (!!e && e.code !== 'EEXIST') {
console.log('Error to create folder: ' + err);
}
require.cache.per.mk = true;
next();
});
} else {
next();
}
};
}
My Question is should I use promise here or not, what is recommended ? The code is working as expected...