I am looking to process a text file using node using a command line call like:
node app.js < input.txt
Each line of the file must be processed individually, but after processing the input line can be forgotten.
Using the on-data listener for stdin, I get the input pair placed byte size, so I set it.
process.stdin.resume(); process.stdin.setEncoding('utf8'); var lingeringLine = ""; process.stdin.on('data', function(chunk) { lines = chunk.split("\n"); lines[0] = lingeringLine + lines[0]; lingeringLine = lines.pop(); lines.forEach(processLine); }); process.stdin.on('end', function() { processLine(lingeringLine); });
But it seems so messy. It is necessary to massage the first and last elements of the line array. Is there a more elegant way to do this?
Matt R. Wilson Nov 20 '13 at 3:39
source share