Skip to content

Instantly share code, notes, and snippets.

@maxjing
Created January 19, 2019 00:27
Show Gist options
  • Save maxjing/7f17e3681e4d56b9ca8ef0f6f990ac88 to your computer and use it in GitHub Desktop.
Save maxjing/7f17e3681e4d56b9ca8ef0f6f990ac88 to your computer and use it in GitHub Desktop.
javascript readline
const instream = fs.createReadStream(
path.join(__dirname, `../reports/trendData`, `${type}.json`)
);
const outstream = new stream();
const rl = readline.createInterface(instream, outstream);
const labels = [];
rl.on("line", function(line) {
labels.push(line.slice(-19, -5));
});
const scores = require("../reports/trendData/data/scores.json");
rl.on("close", function() {
res.json({ id: type, labels: labels, scores: scores });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment