how to fix this error TypeError [ERR_INVALID_CALLBACK]: Callback must be a function

前端 未结 6 1798
无人及你
无人及你 2021-01-03 18:10

I am a beginner to the nodejs. When I type the below, the code error occurs like this:

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function

6条回答
  •  时光说笑
    2021-01-03 18:41

    Fs.writeFile() according to the documentation here takes ( file, data[, options]and callback ) params so your code will be like this :

     var fs = require('fs');
     fs.readFile('readMe.txt', 'utf8', function (err, data) {
      fs.writeFile('writeMe.txt', data, function(err, result) {
         if(err) console.log('error', err);
       });
     });
    

提交回复
热议问题