无法使用asynchronous瀑布运行parse-csv函数

我试图请求一个URL,从它获得一个CSV文件,然后将该CSV变成JSON。 我正在使用请求 , asynchronous和csvparsing器

我有这个代码:

var fs = require('fs'), async = require('async'), request = require('request'), csv = require('csv-parser'), fileUrl = 'http://forever.codeforamerica.org/fellowship-2015-tech-interview/Violations-2012.csv' var getData = function(cb){ request(fileUrl, function(err, response, body){ (err) ? cb(err) : cb(null, body); }) }; var parseCsv = function(csvData, cb){ var violations = []; fs.createReadStream(csvData) .pipe(csv()) .on('data', function(violation){ violations.push(violation) }) .on('end', function(){ cb(null, violations) }) } // run the functions async.waterfall([ getData, parseCsv ], function(err, results){ if (err) return err; console.log('this does not log') }) 

我得到的文件很好,但每次注销csv数据,而不是JSON,无论我console.log

pipe道未正确处理,您可以直接将“请求”响应传递给pipe道。

 var fs = require('fs'), async = require('async'), request = require('request'), csv = require('csv-parser'), fileUrl = 'http://forever.codeforamerica.org/fellowship-2015-tech-interview/Violations-2012.csv'; var parseCsv = function(cb){ var violations = []; request.get(fileUrl) .pipe(csv()) .on('data', function(violation){ violations.push(violation); }) .on('end', function(){ cb(null, violations); }); }; // run the functions async.waterfall([ parseCsv ], function(err, results){ console.log(err, results); }); 

输出:

{violation_id:'225880',inspection_id:'289908',violation_category:'Unsanitary Conditions',violation_date:'2012-10-17 00:00:00',violation_date_closed:'2012-11-08 00:00:00',违规types:'不卫生地板或墙'},{violation_id:'225905',inspection_id:'289962',violation_category:'植被',violation_date:'2012-10-26 00:00:00',violation_date_closed:'2013-01 -07 00:00:00',violation_type:'Overgrown Vegetation'},{violation_id:'224854',inspection_id:'288325'

PS: 在这里类似的问题