Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
Node resolving not-awaited promises in main script

Why is "timeout' printed by node before terminating when I execute the following code ?

const shouldNotPrint = async () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log('timeout')
      resolve('foo')
    }, 300)
  })
}

shouldNotPrint()
console.log('ended')

Running the previous code with node 16.13.0 will output

> node src/index.js
ended
timeout

Is there some kind of top-level await in node waiting for all promises to resolve before ending the process ?

To clarify: I do not want to terminate Node before the end of my promise. I just want to understand, at a low level, the behavior of node and the event-loop in that case. I understand the logic of a timeout + promise and why it would be printed after "ended". The question is why it is displayed at all and why Node is waiting for it to be displayed before terminating the process.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda