2

I am not able to run the server ...... I am getting the error as ECONNREFUSED

How to resolve this Error !

When i tried to use different ports .... all are giving me the same error !

ubuntu@ip-MyIP:~/rainmelon/projects/FindMyBuffet$ node app.js
Express server listening on port 7005

Error: connect ECONNREFUSED
    at errnoException (net.js:884:11)
    at Object.afterConnect [as oncomplete] (net.js:875:19)
    --------------------
    at Handshake.Sequence (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:20)
    at new Handshake (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12)
    at Protocol.handshake (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/protocol/Protocol.js:42:50)
    at Connection.connect (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/Connection.js:73:18)
    at Object.<anonymous> (/home/ubuntu/rainmelon/projects/FindMyBuffet/app.js:15:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

3 Answers3

5

The traceback says where the exception is coming from:

Error: connect ECONNREFUSED
    at errnoException (net.js:884:11)
    at Object.afterConnect [as oncomplete] (net.js:875:19)
    --------------------
    ...
    at Connection.connect (.../node_modules/mysql/lib/Connection.js:73:18)
-->                                         ^^^^^
    at Object.<anonymous> (/home/ubuntu/rainmelon/projects/FindMyBuffet/app.js:15:12)
-->                                                                     ^^^^^^^^^

So your app can't connect to MySQL.

This is usually down to either incorrect hostname/portname in your MySQL driver configuration, the MySQL server not running, or that your MySQL server isn't configured to listen on TCP sockets. See here.

Community
  • 1
  • 1
robertklep
  • 174,329
  • 29
  • 336
  • 330
  • My express server was functioning correctly ....all of a sudden it stopped .... when i checked it it was showing this error ...in server..... this error was caused when i had made no changes to my previous code .... & i did check your solution.... still same error is popping again ... any ideas ? –  Oct 01 '13 at 10:08
  • 1
    @smriti2 what's at line 15 of your `app.js` file? – robertklep Oct 01 '13 at 10:33
  • @smriti2 perhaps you should edit your answer and post some code, esp where the error occurs. Hard to debug from just an error message. – robertklep Oct 01 '13 at 10:40
  • 1
    I resolved the error ........... With your input(I identified that Mysql had stopped & i didnt knwq abt it) ..... I restarted the mysql server ..... now its functioning ..... thanks !........... i used sudo /etc/init.d/mysql start –  Oct 01 '13 at 10:42
  • @smriti2 glad to hear it's solved, I added the MySQL server being down as another reason why the error might occur :-) – robertklep Oct 01 '13 at 10:52
0

Your mysql process is down, which means it is not running. You need to restart your mysql process (changing ports wont help). To solve this problem you need to restart it. You can do by doing any of the following:

  1. You can start your wamp or xamp server which will automatically start the process.
  2. Or you can open the commandline prompt and start it manually like so "c:\wamp\bin\mysql\mysql5.5.24\bin\mysqld.exe"

Note that using the second method will require knowing the exact location of your wamp folder like I have used mine up top.(in quotes)

dazzledax
  • 1
  • 1
-1

You may do a netstat to find out the pid of process running on the port 7005 and then go for a forceful kill with the pid got.

like

 netstat -plten |grep 7005
 kill -9 16085

where 16085 is the pid obtained from prev command. And restart the express app.

reference

How to kill a process running on particular port in Linux?

Community
  • 1
  • 1
Mithun Satheesh
  • 25,056
  • 14
  • 73
  • 97
  • I tried using the first one of your commands .... i get the error as ... ((Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.)) –  Oct 01 '13 at 08:28
  • i was in root directory when i was using it .... ...one more thing .... all the ports are behaving like this .... is this can be server error ... or should i apply something else ? –  Oct 01 '13 at 08:29
  • @smriti2 : so may be you should try running your express app as root. – Mithun Satheesh Oct 01 '13 at 08:32
  • `ECONNREFUSED` is not the error you get when there's already something listening on a port you're trying to bind to, that's `EADDRINUSE`. – robertklep Oct 01 '13 at 09:11