-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathline_by_line.js
41 lines (31 loc) · 1.18 KB
/
line_by_line.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Created by Zeeshan on 3/6/2016.
*/
//------------------------------------------------------
//read file line by line using module tail
//Web Link=> http://stackoverflow.com/questions/35823597/nodejs-reading-line-by-line-function-while-loop/35823722#35823722
//------------------------------------------------------
/*
var Tail = require('tail').Tail;
var tail = new Tail("./sample_files/file1.txt");
tail.on("line", function(data) {
console.log(data);
});
tail.on("error", function(error) {
console.log('ERROR: ', error);
});
*/
//------------------------------------------------------
//read file line by line using module fs and async
//Web Link=> http://stackoverflow.com/questions/35823597/nodejs-reading-line-by-line-function-while-loop/35823722#35823722
//------------------------------------------------------
var readline = require('linebyline'),
rl = readline('./sample_files/file1.txt');
rl.on('line', function (line, lineCount, byteCount) {
console.log(lineCount, line, byteCount);
// do something with the line of text
})
.on('error', function (e) {
console.log("error", e);
// something went wrong
});