1

I'm building a Node script using event-stream that iterates through a file line-by-line via the split() method and I would like to reference the line number in the resulting output. Is this possible in my implementation?

```

var s = fs.createReadStream(entry.fullPath)
    .pipe(es.split())
    .pipe(es.mapSync(function(line) {
        // How can I get line number here?
})

```

Lounge9
  • 1,213
  • 11
  • 22

1 Answers1

0

You can do it like this but maybe there is a better way.

var lineNumber = 0;

var s = fs.createReadStream(entry.fullPath)
    .pipe(es.split())
    .pipe(es.mapSync(function(line) {
        console.log(lineNumber, line);
        lineNumber++;
})
Jake
  • 1,339
  • 9
  • 14