Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
derKuba opened this issue Dec 6, 2016 · 9 comments
Open

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

derKuba opened this issue Dec 6, 2016 · 9 comments

Comments

@derKuba
Copy link

derKuba commented Dec 6, 2016

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
Copy link

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

@ijkl444
Copy link

ijkl444 commented Dec 18, 2016

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

@barroudjo
Copy link

barroudjo commented Mar 31, 2017

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
Copy link

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
Copy link

andrhamm commented Jul 16, 2018

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
Copy link

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

@dannykennedy
Copy link

dannykennedy commented Sep 9, 2020

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
Copy link

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
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants