简体   繁体   English

无法使用Node.js与Heroku上的ClearDB MySQL连接

[英]Unable to connect with ClearDB MySQL on Heroku using Node.js

Basically, I have an app deployed on Heroku. 基本上,我在Heroku上部署了一个应用程序。 Right now, I am trying to connect with ClearDB add-ons but having some weird errors. 现在,我正在尝试连接ClearDB附加组件,但是出现一些奇怪的错误。

Here is my Heroku config : 这是我的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

And here is my code using Nodejs 这是我使用Node.js的代码

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]);
    });
});

However, when I try to open my app, it's crashed ... Here's my Heroku logs : 但是,当我尝试打开我的应用程序时,它崩溃了……这是我的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

You have no comma in your variable man. 您的可变人中没有逗号。

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

Next time you can see the error logs and debug it. 下次您可以查看错误日志并进行调试。

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.004884 + 00:00 app [web.1]:/app/bot.js:27 2017-10-11T03:29:07.004904 + 00:00 app [web.1]:数据库: 'heroku_1d0d2358c241fd0'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM