Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

373
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda