Skip to content

Instantly share code, notes, and snippets.

@jwadhwani
Last active April 4, 2016 03:28
Show Gist options
  • Save jwadhwani/20f63e56c764bf0d57c5c6f9f00ce048 to your computer and use it in GitHub Desktop.
Save jwadhwani/20f63e56c764bf0d57c5c6f9f00ce048 to your computer and use it in GitHub Desktop.
Check if a directory exists in NodeJS
//sync
try{
fs.statSync('../testing');
}catch(e){
console.log(e.message);//ENOENT: no such file or directory, stat '../testing'
}
//async
fs.stat('../testing', function(err, res){
if(err){
console.log(err.message);//ENOENT: no such file or directory, stat '../testing'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment