Im new to promise topic and I wonder if I write this following code as it should be .
We are using at our project bluebird
This is the code:
var start = function (destination ){
return new Promise(function (resolve, reject) {
fs.readdir(destination, function (err, values) {
if (err) {
reject(err);
} else {
values.reverse();
var flag = true;
values.forEach(function (file) {
if (flag) {
flag = false;
resolve();
} else {
fs.unlink(destination + '/' + file, function (err) {
if (err) {
console.log('Error ' + err);
reject(err);
} else {
console.log('sucess ' + dest + '/' + file);
resolve();
}
});
}
});
}
});
});
};