Node.js Error: connect ECONNREFUSED

后端 未结 12 1047
小鲜肉
小鲜肉 2020-12-02 16:39

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

相关标签:
12条回答
  • 2020-12-02 16:58

    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

    0 讨论(0)
  • 2020-12-02 16:59

    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

    0 讨论(0)
  • 2020-12-02 16:59

    Same error occurs in localhost, i'm just changing the mysql port (8080 into localhost mysql port 5506). it works for me.

    0 讨论(0)
  • 2020-12-02 17:00

    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.

    0 讨论(0)
  • 2020-12-02 17:00

    If you are on MEAN (Mongo-Express-AngularJS-Node) stack, run mongod first, and this error message will go away.

    0 讨论(0)
  • 2020-12-02 17:06

    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.

    0 讨论(0)
提交回复
热议问题