title: Error: connect ETIMEDOUT while connecting to host
body: <p>I am new to nodejs and socket.io i try to make a simple chat through socket.io, connecting with my database.But have an issue while am connecting to host using node.js. I am using amazon server. Please help me to solve this.
      This is my code :- </p>
  
  <pre><code>    var bodyParser = require('body-parser');
      var express = require('express');
      var config = require('./config/config');
      var io = require('socket.io')();
      var openDB = require('json-file-db');
      var db = openDB('db.json');
      var mysql = require('mysql');
      var gcm = require('node-gcm-service');
      var apn = require('apn');
  
      var app = express();
      app.listen(config.HTTP_PORT); // 3000
      app.use(bodyParser.json());
  
      io.listen(config.SOCKET_PORT);//7777
  
      console.log("Server is up");
      var connection = mysql.createConnection({
  
      host : 'xx.xx.xxx.xxx',
      user : 'root',
      password : 'my_password',
      database : 'my_db'
      });
  
      connection.connect(function(error){
          if(!!error)
          {
              console.log(error);
              console.log('Error');
          }
          else
          {
              console.log('connected');
          }
      });
  
  
  
  Error: connect ETIMEDOUT
  at Connection._handleConnectTimeout (/var/www/html/server1/node_modules/mysql/lib/Connection.js:425:13)
  at Socket.g (events.js:286:16)
  at emitNone (events.js:86:13)
  at Socket.emit (events.js:185:7)
  at Socket._onTimeout (net.js:333:8)
  at tryOnTimeout (timers.js:228:11)
  at Timer.listOnTimeout (timers.js:202:5)
  --------------------
  at Protocol._enqueue (/var/www/html/server1/node_modules/mysql/lib/protocol/Protocol.js:141:48)
  at Protocol.handshake (/var/www/html/server1/node_modules/mysql/lib/protocol/Protocol.js:52:41)
  at Connection.connect (/var/www/html/server1/node_modules/mysql/lib/Connection.js:136:18)
  at Object. (/var/www/html/server1/app1.js:35:16)
  at Module._compile (module.js:541:32)
  at Object.Module._extensions..js (module.js:550:10)
  at Module.load (module.js:458:32)
  at tryModuleLoad (module.js:417:12)
  at Function.Module._load (module.js:409:3)
  at Module.runMain (module.js:575:10)
  errorno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',
  fatal: true
  </code></pre>