I am trying to start using Sequelize. I encountered some errors, although I found out and cleared some of them, but I can not understand.
Project Structure:
Project -Client -Server --models ---index.js ---Sid.js --router ---routes ----signup.js ---index.js app.js
my config varriable:
"Lexstart": { "dbConfig": { "driver": "mysql", "user": "root", "database": "sid1", "password": "sid1", "host": "127.0.0.1", "port": "3306" } }
My models /index.js:
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) && (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;
models / Sid.js
module.exports = function(sequelize, DataTypes) { var Sid = sequelize.define("Sid", { username: DataTypes.STRING, password: DataTypes.STRING }); return Sid; };
my router /index.js
module.exports = function (app) {
my router / routes / signup.js
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;
The localhost route: 3000 / signup / sid is working fine. But / signup refuses errors. As you can see in the error text below, it shows that the connection is checked without the value of the parameter provided by the configuration (username, password, host) (the configuration variable works and gets a penalty). I cannot figure this out during debugging.
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.<anonymous> (/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)
Please guide.
Siddhart