Skip to content

Instantly share code, notes, and snippets.

@nicolasembleton
Forked from FGRibreau/existsSync.js
Last active April 8, 2018 02:02
Show Gist options
  • Save nicolasembleton/36d69a62dcb640aec7fb to your computer and use it in GitHub Desktop.
Save nicolasembleton/36d69a62dcb640aec7fb to your computer and use it in GitHub Desktop.
/*
fileExistSync - Check if a file exist in NodeJS
Twitter: @FGRibreau / fgribreau.com
Usage:
var fileExistSync = require('./fileExistSync');
var exist = fileExistSync('/var/folders/zm/jmjb49l172g6g/T/65b199');
Support for Nodev0.6
*/
var fs = require('fs');
module.exports = fs.existsSync || function existsSync(filePath){
try{
fs.statSync(filePath);
}catch(err){
if(err.code == 'ENOENT') return false;
}
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment