如何修复此错误 TypeError [ERR_INVALID_CALLBACK]: Callback must be a function [英] how to fix this error TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
本文介绍了如何修复此错误 TypeError [ERR_INVALID_CALLBACK]: Callback must be a function的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 nodejs 的初学者.当我输入以下内容时,代码错误如下:
I am a beginner to the nodejs. When I type the below, the code error occurs like this:
TypeError [ERR_INVALID_CALLBACK]: 回调必须是一个函数
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
var fs = require('fs');
fs.readFile('readMe.txt', 'utf8', function (err, data) {
fs.writeFile('writeMe.txt', data);
});
推荐答案
Fs.writeFile()
根据文档 这里 需要(file, data[, options] and callback ) params 所以你的代码会是这样的:
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);
});
});
这篇关于如何修复此错误 TypeError [ERR_INVALID_CALLBACK]: Callback must be a function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文