Sequelize Authentication cannot complete
Solution 1
Authenticate returns a Promise in the later versions of sequelize: https://github.com/sequelize/sequelize/blob/2.0/lib/sequelize.js#L939
Read the bluebird documentation here as it is quite useful: https://github.com/petkaantonov/bluebird/blob/master/API.md
Something like this should work (make sure you check for connection errors...this is just a simple example):
var Sequelize = require('sequelize');
var sql = new Sequelize('DB', 'UNAME', 'PASS', {
host: 'localhost',
port: 3306,
dialect: 'mysql'
});
var test = sql.authenticate()
.then(function () {
console.log("CONNECTED! ");
})
.catch(function (err) {
console.log("SOMETHING DONE GOOFED");
})
.done();
Solution 2
Hi sequelize changed their auth scheme in latest release.. Please revert back to older version and try it
Solution 3
you were right!! ;) I just remove sequelize and then reinstall an old veriosn:
npm install [email protected]
and it works!!
I didn't found any info about that... Shouldn't they warn users from deprecated or modified functions ?¿?...
THANKS!! ;)
charly rl
Updated on July 03, 2022Comments
-
charly rl almost 2 years
I'm starting out with node.js and sequelize and I get the following error:
/home/cbaket/test/test.js:9 .complete(function(err) { ^ TypeError: undefined is not a function at Object.<anonymous> (/home/cbaket/test/test.js:9:6) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:501:10) at startup (node.js:129:16) at node.js:814:3
My file: test.js is:
var Sequelize = require('sequelize'); var sequelize = new Sequelize('apidb', 'apidb', 'apidb', { dialect: "mysql", // or 'sqlite', mysql', 'mariadb' port: 3306 // or 5432 (for postgres) }); sequelize .authenticate() .complete(function(err) { if (!!err) { console.log('Unable to connect to the database:', err) } else { console.log('Connection has been established successfully.') } });
I'm following one of the early tutorials on the Sequelieze website.
I installed the latest sequelize and mysql with the following command.
$ npm install mysql $ npm install sequelize
I have tried a lot of similar examples and always get the same error. The libraries are working because other examples work fine, i could create tables in the database and get data from it but the authenticate function always fails.
Thanks! ;)