Read file line as array
JavaScript Makefile
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
test
.gitignore
.jshintignore
.jshintrc
.travis.yml
LICENSE
Makefile
README.md
appveyor.yml
index.js
package.json

README.md

Readlines

Greenkeeper badge Build Status Build status Coverage Status

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);
          }
      });

License

The MIT License