Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!