Intereting Posts

Node.js + Bluebird + csv:额外项目

我有下面的代码下载CSV文件:

function download_csv(symbol) { var req_url = url + '&s=' + symbol var filename = '/prices/' + symbol + '.csv' return request.getAsync(req_url) .then(function(resp) { fs.writeFileAsync(filename, resp) }) } Promise.map(symbols, download_csv, {concurrency: 128}) .error(function(e) {console.error('error ocurred: ', e.message)}) .done(function() {console.log('done')}) 

当我打开csv文件时,第一行右移1列:

 [object Object] Date Open High Low Close Volume Adj Close 

第一列应该说Date,而不是[object Object]。 我的代码中有什么错误?

Solutions Collecting From Web of "Node.js + Bluebird + csv:额外项目"

值是你可以.spread[response, body]的数组。

 function download_csv(symbol) { var req_url = url + '&s=' + symbol var filename = '/prices/' + symbol + '.csv' return request.getAsync(req_url).spread(function(response, body) { // Also add return statement here, very important return fs.writeFileAsync(filename, body) }) } 

这是因为callback签名是:

 callback(err, response, body)