简体   繁体   中英

Getting Error: connect ECONNREFUSED 127.0.0.1:3306

I am a beginner to node.js and was following a tutorial on how to set up a node.js server for Android. When I executed this command, nodemon app.js I am getting this error

[nodemon] 1.19.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`
--Server started at port: 8080--
Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1054:14)
    --------------------
    at Protocol._enqueue (F:\soi19\android-login-register-system\server\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Protocol.handshake (F:\soi19\android-login-register-system\server\node_modules\mysql\lib\protocol\Protocol.js:51:23)
    at Connection.connect (F:\soi19\android-login-register-system\server\node_modules\mysql\lib\Connection.js:119:18)
    at Object.<anonymous> (F:\soi19\android-login-register-system\server\routes.js:8:4)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)

I have tried other answers like changing host: 'localhost' to host:'127.0.0.1' and similarly others but none of them are working. Any help would be appreciated.

While running server: opened server on {"address":"::","family":"IPv6","port": 39333 }

While running client:

  events.js:298
  throw er; // Unhandled 'error' event
  Error: connect ECONNREFUSED 127.0.0.1:50302
  at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
  Emitted 'error' event on Socket instance at:
  at emitErrorNT (internal/streams/destroy.js:84:8)
  at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 50302
  }

I got this server while using node.js net.

Solution:

Make sure that you using the same port numbers in both the client and server apps while working with Node.js net. The port number for server app changes dynamically every time you restart the server. First start the server, note down the port number and then use the same port number for client app. Hope this helps!

I got the same problem about a litle node project. To solve this,I suggest you to

Try to change the hostname 'localhost' to 127.0.0.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM