nickewing / line-reader

Asynchronous line-by-line file reader for node.js
MIT License
452 stars 76 forks source link

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

Open derKuba opened 7 years ago

derKuba commented 7 years ago

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?

stevehobbsdev commented 7 years ago

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

ijkl444 commented 7 years ago

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

barroudjo commented 7 years ago

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();
    });
  });
trappedinspacetime commented 7 years ago

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.

andrhamm commented 6 years ago

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) => {
  // ...
}
CanyonCasa commented 4 years ago

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

dannykennedy commented 4 years ago

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
});
Davetherave2010 commented 3 years ago

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

trappedinspacetime commented 3 years ago

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/