I have code like this which checks for existence of directory before reading the directory:
const fs = require(\'fs\'); fs.exists(dir, function (exists) {