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?
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
}
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With