我正在尝试在节点中发送 http 响应以在浏览器中打印结果。简化的源代码如下。基本上,所有变量都在程序中的某个地方定义,所以这不应该是问题。当我尝试运行脚本时,我不断收到错误消息:
http.js:783
throw new TypeError('first argument must be a string or Buffer');
TypeError: first argument must be a string or Buffer
那么熟悉 node.js 或 javascript 语法的人可以告诉我问题出在哪里吗?
upload = function(req, res) {
var fileInfos = [obj, obj]; //defined as an array of objects
var counter = 0;
counter -= 1;
if (!counter) {
res.end({files: fileInfos}); //files is defined.
}
};
async.forEach(urls, downloadFile, function (err) { //all params defined.
if(err){
console.error("err");
throw err;
}
else{
http.createServer(function(req, res){
upload(req1, res); //req1 defined as an array of objects.
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');
}
});