Skip to content

docs: Add usage example of readline line-by-line parsing #4610

Description

@eljefedelrodeodeljefe

While authoring a parser, I came across what you would normally get in organic search and found lots of it a little dangerous. Namely the use of big module APIs from npm don't occur to make the biggest sense here, since readline has a lot of good functionality built-in. Namely consuming file through readline's interface as steam.

In order to promote use of this, I'd suggest to add an example usage to the docs, which I derived from this stackoverflow link.

This case seemed really common to me, which is why I authored the below PR.

const readline = require('readline');
const fs = require('fs');

const rl = readline.createInterface({
  input: fs.createReadStream('sample.txt')
});

rl.on('line', function (line) {
  console.log('Line from file:', line);
});

PR: #4609

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.readlineIssues and PRs related to the built-in readline module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions