Node.js + Bluebird + csv: extra item [object Object] -
i have following code downloading csv files:
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')})
when open csv file, first row shifted right 1 column:
[object object] date open high low close volume adj close
the first column should date, not [object object]. error in code?
the value array of [response, body]
can .spread
:
function download_csv(symbol) { var req_url = url + '&s=' + symbol var filename = '/prices/' + symbol + '.csv' return request.getasync(req_url).spread(function(response, body) { // add return statement here, important return fs.writefileasync(filename, body) }) }
this because callback signature is:
callback(err, response, body)
Comments
Post a Comment