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

259
Vistas
How to prevent node process exit in a callback?

For example if there is a callback function, after running the callback function, runprocess.exit()

function Test(callback) {
  callback();
  return process.exit();
}

How can I prevent process.exit() execute or prevent process exit in the callback function.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

You could throw an exception at the end of the callback function and catch it outside Test:

function Test(callback) {
  callback();
  return process.exit();
}

try {
  Test(() => {
    console.log('some code');
    throw 'Exception';
  });
} catch {}

console.log('process.exit() skipped');

Running example with exception : https://wandbox.org/permlink/UtDdMh4cHjUPURB8

Running example without exception: https://wandbox.org/permlink/Ih5L1PG1gJKMTJYN

about 4 years ago · Santiago Gelvez Denunciar
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