I'm making a function that returns a boolean for when a file exists or not, using fs.statSync
. It looks like this:
function doesExist (cb) {
let exists
try {
fs.statSync('./cmds/' + firstInitial + '.json')
exists = true
} catch (err) {
exists = err && err.code === 'ENOENT' ? false : true
}
cb(exists)
}
Example use case:
let fileExists
doesExist('somefile.json', function (exists) {
fileExists = exists
})
However, running the code throws me a TypeError: string is not a function
. I have no idea why.
doesExist
function hasn't declared thefirstInitial
parameter in its parameter list:function doesExist(firstInitial, cb) {
*sync
function?