Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

372
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda