5

I have a database that i have previously been accessing (using php) remotely now i am trying to setup sequelize to connect to the same remote servers database:

for this i have the following json (database.json):

{
  "dev": {
    "server": "serverip",
    "driver": "mysql",
    "user": "username",
    "port": "3306",
    "database": "databasename",
    "password": "password"
  }
}

(ive excluded sensitive data)

Now the way i connect to the database from my server.js is:

    var env = app.get('env') == 'development' ? 'dev' : app.get('env');
var port = process.env.PORT || 8080;

var Sequelize = require('sequelize');

// db config
var env = "dev";
var config = require('./database.json')[env];
var password = config.password ? config.password : null;

// initialize database connection
var sequelize = new Sequelize(
    config.server,
    config.database,
    config.user,
    config.port,
    config.password,
    {
        logging: console.log,
        define: {
            timestamps: false
        }
    }
);

The "sad" thing about this is that i does not throw any errors but i know it is not connected because it does not collect any data from the database.

So what am i doing wrong?

1 Answer 1

8

Look at the API docs for creating a new sequelize instance: http://docs.sequelizejs.com/en/latest/api/sequelize/

Only database, user and password should passed as arguments, the rest is in the options object.

var sequelize = new Sequelize(
    config.database,
    config.user,
    config.password,
    {
        port: config.port,
        host: config.server,
        logging: console.log,
        define: {
            timestamps: false
        }    
    }
);
Sign up to request clarification or add additional context in comments.

8 Comments

Hey again @Jan ive passed the variables you suggest however it still does not connect
What happens when you try to run a query then? You must be getting some kind of error message?
No error messages all i get it "something is happening"
What do you mean you get "something is happening" - is that message printed to the console? That does not come from sequelize code, I can asure you.
i found an error message which is kinda odd ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'109.56.7.58' (using password: YES) the problem is that the ip is not the one i instered into the server variable???
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.