Why my callback function is not firing?

Hello, I’m using the fs.writeFile function, here is my code:

    fs.writeFileSync('database.json', JSON.stringify(tasksArray), (err) => {
      if (err) throw err;
      else console.log("The files was added".white.bgGreen)
    })

It is working, however it’s not console logging “The file was added”, why is that happening if error is not occuring?

According to https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options sync function doesn’t take callback.

1 Like

You aren’t using the writeFile function.

As @jenovs says, the synchronous version doesn’t take a callback: it’s synchronous, it’s just ignoring the second argument

1 Like