【问题标题】:Unable to connect with ClearDB MySQL on Heroku using Node.js无法使用 Node.js 连接 Heroku 上的 ClearDB MySQL
【发布时间】:2017-10-11 13:04:17
【问题描述】:

基本上,我在 Heroku 上部署了一个应用程序。现在,我正在尝试连接 ClearDB 插件,但出现了一些奇怪的错误。

这是我的 Heroku 配置:

C:\Users\GDrAnimal\Self-Project\Facebook Bot>heroku config
=== arcane-forest-17003 Config Vars
DATABASE_URL: mysql://b9490a25809735:37eb78b5@us-cdbr-iron-east-05.cleardb.net/heroku_1d0d2358c241fd0?reconnect=true

这是我使用 Nodejs 的代码

var mysql = require('mysql');

//Database
var connection = mysql.createConnection({
    host: "us-cdbr-iron-east-05.cleardb.net",
    user: "b9490a25809735",
    password: "37eb78b5"
    database: 'heroku_1d0d2358c241fd0'
});

connection.connect();

app.get('/', (req, res) => {
    connection.query('SELECT * from Student_Bot', function(err, rows, fields) {
        if (err) {
            console.log('Error Reported ', err);
            throw err;
        }
        res.send(['Hello World!!!! HOLA MUNDO!!!!', rows]);
    });
});

但是,当我尝试打开我的应用程序时,它崩溃了... 这是我的 Heroku 日志:

2017-10-11T03:29:02.994422+00:00 app[web.1]: SyntaxError: Unexpected 
identifier
2017-10-11T03:29:02.994423+00:00 app[web.1]:     at createScript 
(vm.js:56:10)
2017-10-11T03:29:02.994423+00:00 app[web.1]:     at Object.runInThisContext (vm.js:97:10)
2017-10-11T03:29:02.994424+00:00 app[web.1]:     at Module._compile (module.js:542:28)
2017-10-11T03:29:02.994425+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-10-11T03:29:02.994426+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-10-11T03:29:02.994426+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-10-11T03:29:02.994427+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-10-11T03:29:02.994427+00:00 app[web.1]:     at Module.runMain (module.js:604:10)
2017-10-11T03:29:02.994428+00:00 app[web.1]:     at run (bootstrap_node.js:383:7)
2017-10-11T03:29:02.994429+00:00 app[web.1]:     at startup (bootstrap_node.js:149:9)
2017-10-11T03:29:03.094049+00:00 heroku[web.1]: Process exited with status 1
2017-10-11T03:29:03.109659+00:00 heroku[web.1]: State changed from starting to crashed
2017-10-11T03:29:03.113306+00:00 heroku[web.1]: State changed from crashed to starting
2017-10-11T03:29:04.742139+00:00 heroku[web.1]: Starting process with command `node bot.js`
2017-10-11T03:29:07.004884+00:00 app[web.1]: /app/bot.js:27
2017-10-11T03:29:07.004904+00:00 app[web.1]:           database: 'heroku_1d0d2358c241fd0'
2017-10-11T03:29:07.004905+00:00 app[web.1]:           ^^^^^^^^
2017-10-11T03:29:07.004905+00:00 app[web.1]:
2017-10-11T03:29:07.004906+00:00 app[web.1]: SyntaxError: Unexpected identifier
2017-10-11T03:29:07.004907+00:00 app[web.1]:     at createScript (vm.js:56:10)
2017-10-11T03:29:07.004907+00:00 app[web.1]:     at Object.runInThisContext (vm.js:97:10)
2017-10-11T03:29:07.004908+00:00 app[web.1]:     at Module._compile (module.js:542:28)
2017-10-11T03:29:07.004909+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-10-11T03:29:07.004909+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-10-11T03:29:07.004910+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-10-11T03:29:07.004910+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-10-11T03:29:07.004911+00:00 app[web.1]:     at Module.runMain (module.js:604:10)
2017-10-11T03:29:07.004912+00:00 app[web.1]:     at run (bootstrap_node.js:383:7)
2017-10-11T03:29:07.004912+00:00 app[web.1]:     at startup (bootstrap_node.js:149:9)
2017-10-11T03:29:07.086015+00:00 heroku[web.1]: State changed from starting to crashed
2017-10-11T03:29:07.070905+00:00 heroku[web.1]: Process exited with status 1
2017-10-11T04:05:26.000000+00:00 app[api]: Build started by user gdranimal123@gmail.com
2017-10-11T04:05:36.046510+00:00 app[api]: Release v47 created by user gdranimal123@gmail.com
2017-10-11T04:05:36.046510+00:00 app[api]: Deploy 1366f9f3 by user gdranimal123@gmail.com
2017-10-11T04:05:36.525080+00:00 heroku[web.1]: State changed from crashed to starting

【问题讨论】:

    标签: mysql node.js heroku cleardb


    【解决方案1】:

    你的变量 man 中没有逗号。

     password: "37eb78b5"<missing comma>
    database: 'heroku_1d0d2358c241fd0'
    

    下次你可以看到错误日志并调试它。

    2017-10-11T03:29:07.004884+00:00 app[web.1]: /app/bot.js:27 2017-10-11T03:29:07.004904+00:00 应用程序 [web.1]:数据库: 'heroku_1d0d2358c241fd0'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 1970-01-01
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 2013-08-07
      • 1970-01-01
      相关资源
      最近更新 更多