Node.js Error: connect ECONNREFUSED

后端 未结 12 1048
小鲜肉
小鲜肉 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 17:08

    Check with starting mysql in terminal. Use below command

    mysql-ctl start

    In my case its worked

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

    Chances are you are struggling with the node.js dying whenever the server you are calling refuses to connect. Try this:

    process.on('uncaughtException', function (err) {
        console.log(err);
    }); 
    

    This keeps your server running and also give you a place to attach the debugger and look for a deeper problem.

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

    You need to have a server running on port 8080 when you run the code above that simply returns the request back through the response. Copy the code below to a separate file (say 'server.js') and start this server using the node command (node server.js). You can then separately run your code above (node app.js) from a separate command line.

    var http = require('http');
    
    http.createServer(function(request, response){
    
        //The following code will print out the incoming request text
        request.pipe(response);
    
    }).listen(8080, '127.0.0.1');
    
    console.log('Listening on port 8080...');
    
    0 讨论(0)
  • 2020-12-02 17:10

    Run server.js from a different command line and client.js from a different command line

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

    I was having the same issue with ghost and heroku.

    heroku config:set NODE_ENV=production 
    

    solved it!

    Check your config and env that the server is running on.

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

    People run into this error when the Node.js process is still running and they are attempting to start the server again. Try this:

    ps aux | grep node

    This will print something along the lines of:

    user    7668  4.3  1.0  42060 10708 pts/1    Sl+  20:36   0:00 node server
    user    7749  0.0  0.0   4384   832 pts/8    S+   20:37   0:00 grep --color=auto node
    

    In this case, the process will be the one with the pid 7668. To kill it and restart the server, run kill -9 7668.

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