在将nodejs部署到Heroku时抛出错误URL

我有一个node.js服务器在本地主机上成功运行。 但是当我部署到Heroku,服务器崩溃。 我检查本地和heroku有相同的node.js和npm版本。 希望收到你的build议。 谢谢。

这里是消息日志:

2017-01-13T04:16:32.949664+00:00 app[web.1]: > golaundryserver@1.0.0 start /app 2017-01-13T04:16:32.949665+00:00 app[web.1]: > node server.js 2017-01-13T04:16:32.949665+00:00 app[web.1]: 2017-01-13T04:16:33.344617+00:00 app[web.1]: url.js:87 2017-01-13T04:16:33.344629+00:00 app[web.1]: throw new TypeError('Parameter "url" must be a string, not ' + typeof url); 2017-01-13T04:16:33.344630+00:00 app[web.1]: ^ 2017-01-13T04:16:33.344631+00:00 app[web.1]: 2017-01-13T04:16:33.344633+00:00 app[web.1]: TypeError: Parameter "url" must be a string, not undefined 2017-01-13T04:16:33.344634+00:00 app[web.1]: at Url.parse (url.js:87:11) 2017-01-13T04:16:33.344636+00:00 app[web.1]: at Object.urlParse [as parse] (url.js:81:5) 2017-01-13T04:16:33.344636+00:00 app[web.1]: at new Sequelize (/app/node_modules/sequelize/lib/sequelize.js:125:24) 2017-01-13T04:16:33.344637+00:00 app[web.1]: at Object.<anonymous> (/app/db.js:6:17) 2017-01-13T04:16:33.344638+00:00 app[web.1]: at Module._compile (module.js:570:32) 2017-01-13T04:16:33.344638+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10) 2017-01-13T04:16:33.344639+00:00 app[web.1]: at Module.load (module.js:487:32) 2017-01-13T04:16:33.344640+00:00 app[web.1]: at tryModuleLoad (module.js:446:12) 2017-01-13T04:16:33.344640+00:00 app[web.1]: at Function.Module._load (module.js:438:3) 2017-01-13T04:16:33.344641+00:00 app[web.1]: at Module.require (module.js:497:17) 2017-01-13T04:16:33.344642+00:00 app[web.1]: at require (internal/module.js:20:19) 2017-01-13T04:16:33.344642+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:1:72) 2017-01-13T04:16:33.344643+00:00 app[web.1]: at Module._compile (module.js:570:32) 2017-01-13T04:16:33.344643+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10) 2017-01-13T04:16:33.344644+00:00 app[web.1]: at Module.load (module.js:487:32) 2017-01-13T04:16:33.344645+00:00 app[web.1]: at tryModuleLoad (module.js:446:12) 2017-01-13T04:16:33.353999+00:00 app[web.1]: 2017-01-13T04:16:33.362350+00:00 app[web.1]: npm ERR! Linux 3.13.0-105-generic 2017-01-13T04:16:33.362417+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start" 2017-01-13T04:16:33.362573+00:00 app[web.1]: npm ERR! node v6.9.4 2017-01-13T04:16:33.362726+00:00 app[web.1]: npm ERR! npm v4.1.1 2017-01-13T04:16:33.362920+00:00 app[web.1]: npm ERR! code ELIFECYCLE 2017-01-13T04:16:33.363075+00:00 app[web.1]: npm ERR! golaundryserver@1.0.0 start: `node server.js` 2017-01-13T04:16:33.363192+00:00 app[web.1]: npm ERR! Exit status 1 2017-01-13T04:16:33.363477+00:00 app[web.1]: npm ERR! 2017-01-13T04:16:33.363609+00:00 app[web.1]: npm ERR! Failed at the golaundryserver@1.0.0 start script 'node server.js'. 2017-01-13T04:16:33.363736+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed. 2017-01-13T04:16:33.363916+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the golaundryserver package, 2017-01-13T04:16:33.364086+00:00 app[web.1]: npm ERR! not with npm itself. 2017-01-13T04:16:33.364367+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system: 2017-01-13T04:16:33.364662+00:00 app[web.1]: npm ERR! node server.js 2017-01-13T04:16:33.365384+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with: 2017-01-13T04:16:33.365555+00:00 app[web.1]: npm ERR! npm bugs golaundryserver 2017-01-13T04:16:33.365732+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via: 2017-01-13T04:16:33.365933+00:00 app[web.1]: npm ERR! npm owner ls golaundryserver 2017-01-13T04:16:33.366104+00:00 app[web.1]: npm ERR! There is likely additional logging output above. 2017-01-13T04:16:33.370608+00:00 app[web.1]: 2017-01-13T04:16:33.370806+00:00 app[web.1]: npm ERR! Please include the following file with any support request: 2017-01-13T04:16:33.370908+00:00 app[web.1]: npm ERR! /app/npm-debug.log 2017-01-13T04:16:33.450002+00:00 heroku[web.1]: Process exited with status 1 2017-01-13T04:16:33.423935+00:00 heroku[web.1]: State changed from starting to crashed 

从你显示的错误我假设你传递给/app/db.js第6行Sequelize的数据库连接string没有在Heroku上定义,即使它是在你的机器上定义的。

可能的原因可能是你从一个环境variables或一些在你的机器上可用的configuration文件中得到它,但是在Heroku实例上不可用。

看看Sequelize是如何在/app/db.js中初始化的,URL是从哪里来的,也许在那里添加一些console.log(YOUR_VARIABLE_NAME) ,然后试着确定它是应该定义的。

您可以在仪表板中的Heroku上设置您的环境,以便您不必在源代码中添加任何凭据,请参阅: