# File existence promise

I hate to have to write a custom exists promise every time I need to know if a file exists, so I came up with this. Thoughts?

var Promise = require("bluebird")
var fs = Promise.promisifyAll(require("fs"))

function fsExists(_path){
return fs.lstatAsync(_path)
.then(function(){ return true })
.catch(function(){ return false })
}

module.exports = fsExists


I think the catch and then parts are unnecessary. A then accepts a resolve and reject handler, which you can treat a boolean.

var Promise = require("bluebird")
var fs = Promise.promisifyAll(require("fs"))

module.exports = fs.lstatAsync


Usage would simply be

var stat = require('yourFsStatModule');

stat('path/to/file').then(function(){
// it exists
}, function(){
// it doesn't exist
});