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

189
Visualizações
Node not running in expected order

Please excuse the beginner level question here, but on day 2 of Google searching and trying every permutation I can still not making progress on understanding why things are running the order they are.

Given the following code:

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

var username = await rl.question("Pleaser enter username\n");


await axios
  .get('https://somewhere.net/api/something/', {
    headers: {
      Username: username
    }
  })
  .then(res => {
    console.log('statusCode: '+ res.status)
    console.log(res.data.response)
  })
  .catch(error => {
    console.error(error)
  })
  rl.close();

Why am I getting a Username undefined before it even prompts the user for input? I would expect to ask the user for input, then run the axios.

about 4 years ago · Juan Pablo Isaza
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