NODEJS -- fileExists

Check if a file exists in a certain directory
mail@pastecode.io avatar
unknown
javascript
a year ago
221 B
1
Indexable
Never
const fs = require('fs');

// Check if a file exists
fs.access('path/to/file', fs.constants.F_OK, (err) => {
  if (err) {
    console.log('File does not exist');
  } else {
    console.log('File exists');
  }
});