Tuesday 30 May 2017

stuck with node.js Readline module

I am at very entry level with Node.js and JavaScript , i want to read from a txt file line by line and print every single line with adjusted time interval , i found this module which helped me to read lines "https://nodejs.org/api/readline.html" . but my code publish all lines once , i want to wait seconds between lines i added setTimeout function and tried alot of configration with no vail . Thanks

     const readline = require('readline');
     const fs = require('fs');
  const rl = readline.createInterface({
  input: fs.createReadStream(process.cwd() +'/sample.txt')  
 });

 rl.on('line', function(input){
  rl.pause();
  console.log(input);

   setTimeout(() => {
     rl.resume();
    }, 5000);



via Mostafa Radwan

No comments:

Post a Comment