Skip to content

Instantly share code, notes, and snippets.

@albertosouza
Created January 19, 2020 14:43
Show Gist options
  • Save albertosouza/d3db050329a79ab7d8e6606f8ea94ff8 to your computer and use it in GitHub Desktop.
Save albertosouza/d3db050329a79ab7d8e6606f8ea94ff8 to your computer and use it in GitHub Desktop.
Simple script to show how to check if file exists with Node.js
// text.txt file is in same folder where we are running this script
let filePath = path.join(process.cwd(), 'text.txt');
// Check if file exists and have access with fs.access:
fs.access(filePath, fs.F_OK, function (err) {
if (err) {
console.log('file not exists or not have access');
} else {
console.log('file exists');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment