Read lines synchronously from file in Node.js
This project on github.com does exactly what I needed:
https://github.com/nacholibre/node-readlines
var readlines = require('n-readlines');
var liner = new readlines(filename);
var vertexes_number = parseInt(liner.next().toString('ascii'));
var edges_number = parseInt(liner.next().toString('ascii'));
var edges = [];
var next;
while (next = liner.next()) {
edges.push(next.toString('ascii').split(' '));
}
My usual code part for such simple tasks:
var lines = require('fs').readFileSync(filename, 'utf-8')
.split('\n')
.filter(Boolean);
lines
is an array of strings without empty ones.