fs.exists
is an oddball in that it doesn't provide an error parameter to its callback function. Instead it only provides a single exists
parameter that indicates whether the file was found or not. Presumably, if there was an error, exists
would be false
. As such you need to wrap its callback in your own function so that you can provide a separate error parameter to the waterfall
callback:
async.waterfall( [
function checkIfFileExists(done) {
fs.exists('file.txt', function(exists) { done(null, exists); });
},
function makeSureFileExists(exists, done) {
...
Note the warning in the docs, however, that fs.exists
shouldn't be used, typically.