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));
});
});