Home > Software design >  TypeError: rl.question is not a function - NodeJS - using play.js
TypeError: rl.question is not a function - NodeJS - using play.js

Time:01-29

I’m trying to use the readline library within play.js which is an iOS app on my iPad.

const rl = require("readline")

rl.createInterface({
  input: process.stdin,
  output: process.stdout
});

var response

rl.question("Enter a number ", function (answer) {
    response = answer
    outside();
    rl.close();
});

outside = function(){
    console.log('The user entered: ', response)
}

And I keep getting the error TypeError: rl.question is not a function

CodePudding user response:

Apparently the readline npm package has been renamed to linebyline because it is now the name of a core module in node 10. I would suggest changing your import like this:

const rl = require("linebyline");

If this does not solve the problem, please check if you installed the correct package. The error seems to indicate that rl.question is undefined.

Edit: My bad, I see now you intended to use the core module. Then maybe check if your node setup works correctly and if the version is recent enough. (Also try adding a ; after var response.)

  •  Tags:  
  • Related