javascript - fs.statSync throws an error when contained in a function? -


i'm making function returns boolean when file exists or not, using fs.statsync. looks 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 code throws me typeerror: string not function. have no idea why.

i think want remove callback, , add file name parameters:

function doesexist(firstinitial) {   try {     fs.statsync('./cmds/' + firstinitial + '.json')     return true   } catch(err) {     return !(err && err.code === 'enoent');   } }  let fileexists = doesexist('somefile'); 

btw, there fs.exists.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -