line-reader icon indicating copy to clipboard operation
line-reader copied to clipboard

lineReader.eachLine(...).then is not a function

Open derKuba opened this issue 8 years ago • 9 comments
trafficstars

When i try to use this code sample...

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

// read all lines:
lineReader.eachLine('file.txt', function(line) {
  console.log(line);
}).then(function (err) {
  if (err) throw err;
  console.log("I'm done!!");
});

... i get this error:

}).then(function (err) { ^ TypeError: lineReader.eachLine(...).then is not a function

Do you have any idea why?

derKuba avatar Dec 06 '16 15:12 derKuba

I'm seeing this as well, using version 0.4.0. Tried to follow the example as given in the documentation.

stevehobbsdev avatar Dec 13 '16 13:12 stevehobbsdev

how can use pause and resume function in the Module? thx~

ijkl444 avatar Dec 18 '16 16:12 ijkl444

Same here... Will try to find a workaround. EDIT: solved it this way:

return new Promise((resolve, reject) => {
    lineReader.eachLine(file, function lineOperation (line, last, cb) {
      doYourThing(line, cb);
    }, function finished (err) {
      if (err) return reject(err);
      resolve();
    });
  });

barroudjo avatar Mar 31 '17 16:03 barroudjo

I get the same error

    TypeError: lineReader.eachLine(...).then is not a function

from https://github.com/wallali/geocoder.js/blob/master/data/build.js I don't know how to fix it.

trappedinspacetime avatar May 19 '17 16:05 trappedinspacetime

Also seeing this issue...

import lineReader from 'line-reader';

export const eachLine = (filename, iteratee) => new Promise(((resolve, reject) => {
  lineReader.eachLine(filename, iteratee, (err) => {
    if (err) {
      reject(err);
    } else {
      resolve();
    }
  });
}));
await eachLine('file.txt', (line) => {
  // ...
}

andrhamm avatar Jul 16 '18 20:07 andrhamm

Documentation (README.md) updated on Github but not NPM site.

CanyonCasa avatar May 17 '20 13:05 CanyonCasa

Reading the documentation now, this is what's recommended:

const lineReader = require("line-reader");
const Promise = require("bluebird");
const eachLine = Promise.promisify(lineReader.eachLine);
eachLine(path, function (line) {
  // do your thing
}).then(() => {
  // All the lines are read
});

dannykennedy avatar Sep 09 '20 06:09 dannykennedy

If you're still having issues, node has an inbuilt module that does the same (and can be easily wrapped in a promise) called readline. Example here - https://daendersby.medium.com/stop-using-line-reader-1ad452f68155

Davetherave2010 avatar Apr 20 '21 12:04 Davetherave2010

If you're still having issues, node has an inbuilt module that does the same (and can be easily wrapped in a promise) called readline. Example here - https://daendersby.medium.com/stop-using-line-reader-1ad452f68155

Reading that article requires subscription. Someone can read it free in the following link: https://stackabuse.com/reading-a-file-line-by-line-in-node-js/

trappedinspacetime avatar Apr 20 '21 14:04 trappedinspacetime