Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

341
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda