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

194
Visualizações
What is the difference between process.exit() vs return when ending the process?

I wrote a code that ends the process under certain conditions, and when I write it as a return, it ends abnormally due to an over-memory error, and process.exit() ends normally.

P.S. My code is just only one function. So the two method quit the one function.

Can you explain the difference between the two methods when ending the process?

if(condition === true)
    process.exit();
if(condition === true)
    return;
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

return will only stop the function that contains the return statement. process.exit will stop all the running functions and stop all the tasks.

So when you call return it will stop the current function but execute the remaining functions.

about 4 years ago · Juan Pablo Isaza Relatório

0

  1. Explicitly calling process.exit forcibly discards some pending asynchronous tasks.

Calling process.exit() will force the process to exit as quickly as possible even if there are still asynchronous operations pending that have not yet completed fully, including I/O operations to process.stdout and process.stderr.

-- https://nodejs.org/api/process.html#process_process_exit_code

  1. process.exit() prevents the beforeExit event from emitting.

The 'beforeExit' event is emitted when Node.js empties its event loop and has no additional work to schedule. Normally, the Node.js process will exit when there is no work scheduled, but a listener registered on the 'beforeExit' event can make asynchronous calls, and thereby cause the Node.js process to continue.

-- https://nodejs.org/api/process.html#process_event_exit

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