I am new to node and running into this error on a simple tutorial.
I am on the OS X 10.8.2 trying this from CodeRunner and the Terminal. I have also tried putting my
Sometimes it may occur, if there is any database connection in your code but you did not start the database server yet.
Im my case i have some piece of code to connect with mongodb
mongoose.connect("mongodb://localhost:27017/demoDb");
after i started the mongodb server with the command mongod this error is gone
The Unhandled 'error' event
is referring not providing a function to the request to pass errors. Without this event the node process ends with the error instead of failing gracefully and providing actual feedback. You can set the event just before the request.write
line to catch any issues:
request.on('error', function(err)
{
console.log(err);
});
More examples below:
https://nodejs.org/api/http.html#http_http_request_options_callback
Same error occurs in localhost, i'm just changing the mysql port (8080 into localhost mysql port 5506). it works for me.
You're trying to connect to localhost:8080 ... is any service running on your localhost and on this port? If not, the connection is refused which cause this error. I would suggest to check if there is anything running on localhost:8080 first.
If you are on MEAN (Mongo-Express-AngularJS-Node) stack, run mongod first, and this error message will go away.
Had a similar issue, it turned out the listening port printed was different from what it actually was. Typos in the request string or listening function might make the target server appear to not exist.