Answers for "nodejs readline stop before read the whole file"

3

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
  // ('rn') 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();
Posted by: Guest on May-17-2021
1

readline node js

readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
})

readline.on("line", (line) => {
    if (line === "") {
        // Code
    }
    else if (line === "") {
        // Code
    }
})
Posted by: Guest on July-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language