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

266
Visualizações
How can I make rl (or prompts) return the value of what the user inputs

How can I get rl.question to return the value that the user inputs, my code looks like this:

const readline = require('readline');
const { stdin: input, stdout: output } = require('process');
    
const rl = readline.createInterface({ input, output });
    
console.log(rl.question("hello?",(answer) => {return answer}))

I know there are probably better modules to use if I want a python-style input function, but 'prompts' seems to have the same problem.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm not super sure what you are asking, so let me know if this isn't it.

ReadLine Docs

To console.log() the answer from a ReadLine question there are multiple methods, here are some.

try moving the console.log inside of the {}

rl.question('hello? ', (answer) => {
 console.log(answer);
 // ... whatever you want to do with the answer variable 
})

or you can use async/await with promise

async function AskQuestion() {
  return new Promise(async (resolve, reject) => {
    rl.question('Hello? ', (answer) => {
      resolve(answer);
    });
  });
}

and then just await the function somewhere

(async () => {
    let answer = await AskQuestion();
    console.log(answer);
})();
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