Sequelize Authentication cannot complete

I start 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:

 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 follow 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 many similar examples and always get the same error. Libraries work because other examples work fine, I can create tables in the database and receive data from it, but the authentication function always fails.

Thanks!;)

+6
source share
4 answers

Authentication returns a promise in later versions of sequelize: https://github.com/sequelize/sequelize/blob/2.0/lib/sequelize.js#L939

Read the bluebird documentation here as it is very useful: https://github.com/petkaantonov/bluebird/blob/master/API.md

Something like this should work (make sure you check for connection errors ... this is 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(); 
+15
source

Hi sequelize changed its authentication scheme in the latest version .. Please revert to the old version and try

+5
source

you were right !;) I just uninstall sequelize and then reinstall the old veriosn:

npm install sequelize@1.7.0

and it works !!

I did not find any information about this ... Should I warn users about outdated or changed features? ¿? ...

THANKS!!;)

+2
source

I suspect you are looking

 Sequelize.authenticate().complete(...) 

instead

 Sequelize.authenticate.complete(...) 

Sequelize.authenticate is a function that returns a promise. This is not an object with the .complete () method. If you do not fulfill it, the promise will not be returned. If the promise is not returned, you cannot execute .complete () on the promise.

Hope this helps you.

Below is the documentation for Promises from the Mozilla Development Network .

0
source

Source: https://habr.com/ru/post/986330/


All Articles