How can I parse records on demand with Node.js? How can I parse records on demand with Node.js? node.js node.js

How can I parse records on demand with Node.js?


As far as I understand, you just want to parse the comma-separated line of values into an array? If so, try this one:

https://npmjs.org/package/csvrow


Parsing a single 'line' (which can also have embedded newlines):

var csv = require('csv'); // node-csvcsv()  .from.string(SINGLE_LINE_OF_CSV)  .to.array(function(record) {    console.log('R', record);  });

I'm not sure what you mean by 'a specific number of records from a CSV file', or what the issue is exactly. Once you've read the amount you need, just send the response back to the client and you're done.

EDIT: if you want to implement paging, you can use node-csv too:

var csv   = require('csv');var skip  = 100;var limit = 10;csv()  .from.path('file.csv')  .on('record', function(row, index) {    if (index >= skip && index < (skip + limit))      console.log('R', index);  });