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

667
Views
process.on('unhandledRejection') is not logging error

In my server.js file i'm trying to log errors and not cause them to crash the app, this is the code im using

const server = app.listen(3000, () =>
    console.log('Server Up and running')
);

process.on('unhandledRejection', (err, promise) => {
    console.log(`Error: ${err}`);
    server.close(() => process.exit(1));
})

when i produce an error instead of it logging the error and closing the server it just logs the error how it normally would and causes the app to crash. If you need more info let me know. Sorry if this is a dumb question

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I suppose you know the difference between Unhandled Rejection and Uncaught Exception.

it just logs the error how it normally would

Because you're console logging the same error object!

Also don't use process.exit(). Because you might lose your logs. read more

Express docs explained how to do graceful shutdown, you can use similar approach.

over 4 years ago · Santiago Trujillo 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!