Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js unhandled 'error' event

I have written a simple code and save it in file try.js .

var http = require('http'); var makeRequest = function(message) {   var options = {     host: 'localhost', port: 8080, path: '/', method: 'POST'   }   var request = http.request(options, function(response){     response.on('data', function(data){       console.log(data);     });   });    request.write(message);   request.end(); } makeRequest("Here's looking at you, kid."); 

When I run it through terminal it give an error

throw er; // Unhandled 'error' event, Error: connect ECONNREFUSED at errnoException (net.js:884:11) at Object.afterConnect [as oncomplete] (net.js:875:19)error' event 
like image 599
ana Avatar asked May 02 '13 06:05

ana


People also ask

Which event is used for unhandled exception in node JS?

js Process uncaughtException Event. The 'uncaughtException' is an event of class Process within the process module which is emitted when an uncaught JavaScript exception bubbles all the way back to the event loop.

How do I restart node JS?

If it's just running (not a daemon) then just use Ctrl-C.

Can Arduino run Nodejs?

Arduino is one single board on which you can do programing and control various devices, you can give output to any device using Arduino and also take some input from the device (sensor). Node. js is a powerful JavaScript-based framework/platform built on Google Chrome's JavaScript Engine.


2 Answers

For me, the problem was another instance was running. Search for other node instance running and kill it. It should resume properly after.

like image 169
MVCaraiman Avatar answered Sep 19 '22 08:09

MVCaraiman


This is happening because nothing is listening on localhost:8080. Here are the examples how to handle request errors How to catch http client request exceptions in node.js

like image 37
Damian Krawczyk Avatar answered Sep 17 '22 08:09

Damian Krawczyk