Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

338
Views
TypeError: rl.question is not a function - NodeJS - using play.js

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

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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.)

about 4 years ago · Juan Pablo Isaza Report

0

Ok I know that I'm three months late but this is my first time replying with an answer that works!!! But anyway the reason that you keep getting an error is because this line

const rl = require("readline")

only pulls the readline module into rl, if you wanted to do anything with readline you need to create an instance of it by doing.

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

and then call the question method from that object like this

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

I'm still learning JS so I could be wrong in my reasoning but the code will work nonetheless :)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!