readlines
v0.2.0
Published
Read file line as array
Downloads
898
Readme
Readlines
Read file line as array.
Install
npm install readlines
or
npm install -g readlines
Example:
var rl = require('readlines');
var lines = rl.readlinesSync('example.txt');
for(var line in lines){
console.log(lines[line]);
};
API
readlinesSync(filename, [options])
Sync read file by line return an array.
var lines = rl.readlinesSync(filePath);
readlines(filename, [options], callback)
Async read file by line return an array.
rl.readlines(filePath, function(err, lines){
console.log(lines);
});
readlineSync(filename, [options], lineNum)
Sync read file by line return specific line.
var line = rl.readlineSync(filePath, 3);
readline(filename, [options], lineNum, callback)
Async read file by line return specific line.
rl.readline(filePath, 3, function(err, line){
console.log(line);
});
readlinesStream()
Read by line as stream.
var liner = rl.readlinesStream();
fs.createReadStream(filePath)
.pipe(liner)
.on('readable', function() {
var line;
while (line = liner.read()) {
console.log(line);
}
});