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

371
Views
How to run a function when nodeapp returns error

I want to be able throw a function when my node app returns error

Let's say I have a simple node app

var express= require('express');
var app = express();
var http = require('http');

app.get('/', function(req, res){
res.send('hello')
})

app.listen(2500);

if there is an error while running the app, it might be related to the port or i might not have a proper node package module installed i just want it to run a function.. how do i do that?

I want it to console.log('node crashed') for example

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can listen for uncaughtException event:

process.on('uncaughtException', err => console.log('Error:', err));

but you should really handle the errors where they appear, so e.g. you should handle the port binding error explicitly:

var server = app.listen(2500);
server.on('error', err => console.log('Listen error:', err.message));

and handle other errors in the same fashion. Otherwise you will not be able to do anything to actually recover from the error, other than saying: oops.

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!