Node-js

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined, someone asked me to explain?
I m using nodejs, I got the following error while appending a file. 
const fs = require('fs');
fs.appendFile('message.txt', 'Hello, user how are you?');


Solution:
The fs.appendFile function expecting third parameter as call back function.
const fs = require('fs');
fs.appendFile('message.txt', 'Hello, user how are you?', (err) => {
    if (err) throw err;
    console.log('The "data to append" was appended to file!');
  });


Related Article

Post your comments / questions