Created
January 19, 2020 14:43
-
-
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
This file contains 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
// 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