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

225
Views
Is there a way to divert logs/errors to run code in pm2?

I want to be able to run code to log the error correctly then crash the process instead of immediately crashing the process if there is an error, like a global try catch. Is there a way to do that? I want a solution like

process.on("uncaughtException", err => {
    logTheErrorSomehow();
    process.exit(1);
});

but that doesn't work in pm2, only node.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After a week of trial and error, I came across this solution that worked:

const pm2 = require('pm2');

pm2.launchBus(function(err, pm2_bus) {
  pm2_bus.on('process:exception', function(packet) {
    await logTheErrorSomehow(packet);
    process.exit(1);
  });
});

This works just like process.on("uncaughtException") did with node.

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