JSPM

read-nth-line

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q45783F
  • License MIT

Get the nth line from a file using sed.

Package Exports

  • read-nth-line
  • read-nth-line/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (read-nth-line) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

read-nth-line

Read the nth line of a file with sed. Your system must have sed available. For large files, this is more efficient than using readline. However, due to the overhead of spawning a shell process, readline is more efficient for smaller files.

Usage

Asynchronous

const nthLine = require('read-nth-line');

nthLine.read(__dirname + '/notes.txt', 150).then(result => {
  console.log(result);
}).catch(err => {
  console.warn(err);
});

Synchronous

const nthLine = require('read-nth-line');

try {
  console.log(nthLine.readSync(__dirname + '/notes.txt', 150));
} catch (err) {
  console.warn(err);
}

The first line in your file is line 0, and if you don't pass in an absolute path, the file path is relative to the directory that node is executing in. Consider using __dirname to fully qualify the file path.