I need to count the lines of a CSV file. If the file is empty, I want to write the columns names as first line, then the info that I need to log.
Any suggestions how to do this?
var i;
var count = 0;
require('fs').createReadStream(process.argv[2])
.on('data', function(chunk) {
for (i=0; i < chunk.length; ++i)
if (chunk[i] == 10) count++;
})
.on('end', function() {
console.log(count);
});
This is a duplicate of Node.js: Count the number of lines in a file, please learn to google your problems first.