Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node read file line

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

async function processLineByLine() {
  const fileStream = fs.createReadStream('input.txt');

  const rl = readline.createInterface({
    input: fileStream,
    crlfDelay: Infinity
  });
  // Note: we use the crlfDelay option to recognize all instances of CR LF
  // ('
') in input.txt as a single line break.

  for await (const line of rl) {
    // Each line in input.txt will be successively available here as `line`.
    console.log(`Line from file: ${line}`);
  }
}

processLineByLine();
Comment

File line by line reader Node js

var lineReader = require('line-reader');

lineReader.eachLine('file.txt', function(line, last) {
  console.log(line);
  // do whatever you want with line...
  if(last){
    // or check if it's the last one
  }
});
Comment

File line by line reader Node js

lineReader.open('file.txt', function(reader) {
  if (reader.hasNextLine()) {
    reader.nextLine(function(line) {
      console.log(line);
    });
  }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: react-native run-ios command 
Javascript :: MVC view pass model to javascript function 
Javascript :: javascript map max value 
Javascript :: lwc quick action close 
Javascript :: react conditional styling 
Javascript :: how to find the index of an item in nodelist in js 
Javascript :: js setinterval 
Javascript :: js for each item in array 
Javascript :: using .includes for an array of objects js 
Javascript :: how to access key of object in javascript 
Javascript :: referenceerror window is not defined ckeditor 
Javascript :: javascript pick random attribute from object 
Javascript :: expo react native 
Javascript :: angularjs accordion access toggle 
Javascript :: js insertbefore 
Javascript :: how to remove first child in javascript 
Javascript :: how remove last letter js 
Javascript :: concat object 
Javascript :: xmlhttprequest javascript 
Javascript :: javascript find all matches in array 
Javascript :: js array two dimensional 
Javascript :: Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax. 
Javascript :: javascript date custom string format 
Javascript :: javascript pluck from array of objects 
Javascript :: href="javascript:void(null);" 
Javascript :: datetime to date moment 
Javascript :: javascript random 
Javascript :: change index array javascript 
Javascript :: filter array inside array 
Javascript :: convert days into year month 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =