Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Prior to Node v0.10 fs.exists() and path.exists() were working
var path = require('path');
path.exists('foo.txt', function(exists) {
if (exists) {
// do something
}
});
if (path.existsSync('foo.txt')) {
// do something
}
fs.stat('foo.txt', function(err, stat) {
if(err == null) {
console.log('File exists');
} else if(err.code == 'ENOENT') {
// file does not exist
fs.writeFile('log.txt', 'Some log\n');
} else {
console.log('Some other error: ', err.code);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question