3

i am trying to get row by row data from a csv file, i want to observe changes in my file and get updated data (update means adding rows to file), so below is the code i tried to do it, its working fine till printing rows but not working from fs.watch file code

i am getting event after change in the file but rows are not transformed

UPDATE :

Is there a way to get data using index value like i know row number and i want to get data of that row and transform and print it

node.js:

var csv = require('csv');
var fs = require('fs');
var str = csv().from.stream(fs.createReadStream('test.csv'))
str.transform( function(row){
  row.unshift(row.pop());
  return row;


})
.on('record', function(row,index){
  console.log('#'+index+' '+JSON.stringify(row));



});

fs.watchFile('test.csv', function (curr, prev) {

 str.transform( function(row){
  row.unshift(row.pop());
  return row;

  }).on('record', function(row,index){
  console.log('#'+index+' '+JSON.stringify(row));
  });
});
Labeo
  • 5,831
  • 13
  • 47
  • 77
  • Try the `chokidar` package http://davidwalsh.name/node-watch-file – Seth Difley Oct 06 '15 at 05:33
  • is there a way that if i specify row number in a file i should get data of that row and i will use that data. – Labeo Oct 06 '15 at 06:28
  • var chokidar = require('chokidar'); var watcher = chokidar.watch('test.csv', { persistent: true });watcher.on('change', function(path, stats) { console.log('event'); str.transform( function(row){ row.unshift(row.pop()); return row; }).on('record', function(row,index){ console.log('#'+index+' '+JSON.stringify(row)); }); }); Its not printing rows – Labeo Oct 06 '15 at 13:03
  • Read Nth line of file in NodeJS http://stackoverflow.com/questions/6394951/read-nth-line-of-file-in-nodejs – CodingDefined Oct 08 '15 at 07:09

0 Answers0