Last active
April 4, 2016 03:28
-
-
Save jwadhwani/20f63e56c764bf0d57c5c6f9f00ce048 to your computer and use it in GitHub Desktop.
Check if a directory exists in NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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