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 :: connect mongoose to atlas 
Javascript :: javascript get month name 
Javascript :: how to delay iterations in javascript 
Javascript :: jquery delete request 
Javascript :: js check if element into view 
Javascript :: javascript stop setinterval 
Javascript :: js stop form submit on enter 
Javascript :: update node .js 
Javascript :: show 5 entries in datatable 
Javascript :: count all elements with class jquery 
Javascript :: remove last character from string js 
Javascript :: regex email js 
Javascript :: javascript get all array elements except last 
Javascript :: js queryselector names 
Javascript :: select a form by name jquery 
Javascript :: discord.js kick user 
Javascript :: javascript on double click 
Javascript :: javascript foreach get key and value 
Javascript :: dropzone clear files 
Javascript :: react font awesome delete icon 
Javascript :: RegExp validation for password explained 
Javascript :: javascript clear style inline property 
Javascript :: get selected text of html dropdown in javascript 
Javascript :: get parameter from next.js route 
Javascript :: javascript generate random string 
Javascript :: Factorial of Number in Javascript using Recursive call in javascript 
Javascript :: delete cr eslint 
Javascript :: jquery empty ul 
Javascript :: javascript sort array of objects by date 
Javascript :: javascript get first 10 characters of string 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =