在致电"然后"

时间:2017-07-02 08:23:10

标签: node.js promise sequelize.js

我正在关注续集入门教程here

我觉得奇怪的是,我的node.js程序在调用then后永远不会退出。

这是我的代码:

// testSequelize.js
const Sequelize = require('sequelize');

let CONN_STRING = `mysql://userName:password@127.0.0.1:3306/databaseName`;

var sequelize = new Sequelize(CONN_STRING, {
    logging: false
});

sequelize
  .authenticate()
  .then(() => {
    console.log('Connection has been established successfully.');
  })
  .catch(err => {
    console.error('Unable to connect to the database:', err);
  });

执行node testSequelize.js的结果是

node testSequelize.js
Connection has been established successfully.

程序只挂在那里,它不会退出。我的意思是执行后我看不到命令​​提示符。

有谁知道为什么它永远不会退出?

我的nodemysql2sequelize的版本分别为6.2.2,1.3.5和4.2.1。

1 个答案:

答案 0 :(得分:1)

它没有退出,因为连接已打开,请尝试关闭它:

...
.then(() => {
  console.log('Connection has been established successfully.');
  sequelize.close();
})
...