title: Error while Accessing mysql through Sequelize (Express/NodeJS)
body: <p>I am trying to start using Sequelize. I am facing some errors though figured and cleared some of them but this one I am unable to figure out.</p>
  
  <p>Project Structure:</p>
  
  <pre><code>Project
   -Client
   -Server
    --models
      ---index.js
      ---Sid.js
    --router
      ---routes
         ----signup.js
      ---index.js
    app.js
  </code></pre>
  
  <p>my config varriable:</p>
  
  <pre><code>"Lexstart": {
    "dbConfig": {
       "driver": "mysql",
       "user": "root",
       "database": "sid1",
       "password": "sid1",
       "host": "127.0.0.1",
       "port": "3306"
    }
  }
  </code></pre>
  
  <p>My models/index.js:</p>
  
  <pre><code>var fs        = require("fs");
  var path      = require("path");
  var Sequelize = require('sequelize');
  var config    = require('config');  // we use node-config to handle environments
  
  var dbConfig = config.get('Lexstart.dbConfig');
  
  // initialize database connection
  var sequelize = new Sequelize(
      dbConfig.database,
      dbConfig.username,
      dbConfig.password,{
        host: dbConfig.host,
        dialect: dbConfig.driver
  }
  );
  var db        = {};
  
  fs
  .readdirSync(__dirname)
  .filter(function(file) {
      return (file.indexOf(".") !== 0) &amp;&amp; (file !== "index.js");
  })
  .forEach(function(file) {
      var model = sequelize.import(path.join(__dirname, file));
      db[model.name] = model;
  });
  
  Object.keys(db).forEach(function(modelName) {
  if ("associate" in db[modelName]) {
      db[modelName].associate(db);
  }
  });
  
  db.sequelize = sequelize;
  db.Sequelize = Sequelize;
  
  module.exports = db;
  </code></pre>
  
  <p>models/Sid.js</p>
  
  <pre><code>module.exports = function(sequelize, DataTypes) {
      var Sid = sequelize.define("Sid", {
          username: DataTypes.STRING,
          password: DataTypes.STRING
       });
  
  return Sid;
  };
  </code></pre>
  
  <p>my router/index.js</p>
  
  <pre><code>/**
  * The Index of Routes
  */
  
  module.exports = function (app) {
  
  // The signup route
  app.use('/signup', require('./routes/signup'));
  }
  </code></pre>
  
  <p>my router/routes/signup.js</p>
  
  <pre><code>var models = require('../../models');
  var Sid = models.Sid;
  // Include Express
  var express = require('express');
  // Initialize the Router
  var router = express.Router();
  var config    = require('config');  // we use node-config to handle environments
  
  
  // Setup the Route
  router.get('/', function (req, res) {
  
  Sid.findAll().then(function(users) {
      console.log(users);;
  });
  
  // return a json response to angular
  res.json({
      'msg': users
  });
  });
  
  router.get('/sid', function (req, res) {
  
  // return a json response to angular
  res.json({
      'msg': "sid"
  });
  });
  
  
  
  // Expose the module
  module.exports = router;
  </code></pre>
  
  <p>The route localhost:3000/signup/sid is working fine. But the /signup is giving up error. As you can see in the error text below it showing that connection is being tried without the config supplied variable value (username, password, host)(The config variable are working and fetching fine). I can't figure this out while debugging also.</p>
  
  <pre><code>Unhandled rejection SequelizeAccessDeniedError: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: YES)
  at Handshake._callback (/Users/siddharthsrivastava/Documents/sites/express/LexStart/server/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:51:20)
  at Handshake.Sequence.end (/Users/siddharthsrivastava/Documents/sites/express/LexStart/server/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
  at Handshake.ErrorPacket (/Users/siddharthsrivastava/Documents/sites/express/LexStart/server/node_modules/mysql/lib/protocol/sequences/Handshake.js:103:8)
  at Protocol._parsePacket (/Users/siddharthsrivastava/Documents/sites/express/LexStart/server/node_modules/mysql/lib/protocol/Protocol.js:274:23)
  at Parser.write (/Users/siddharthsrivastava/Documents/sites/express/LexStart/server/node_modules/mysql/lib/protocol/Parser.js:77:12)
  at Protocol.write (/Users/siddharthsrivastava/Documents/sites/express/LexStart/server/node_modules/mysql/lib/protocol/Protocol.js:39:16)
  at Socket.&lt;anonymous&gt; (/Users/siddharthsrivastava/Documents/sites/express/LexStart/server/node_modules/mysql/lib/Connection.js:96:28)
  at Socket.emit (events.js:107:17)
  at readableAddChunk (_stream_readable.js:163:16)
  at Socket.Readable.push (_stream_readable.js:126:10)
  at TCP.onread (net.js:538:20)
  </code></pre>
  
  <p>Please guide.</p>
  
  <p>Siddharth</p>