我有一个node.js服务器在localhost中成功运行。但是当我部署到Heroku时,服务器崩溃了。我检查了local和heroku是否有相同的node.js和npm版本。 希望得到你的建议。 谢谢。
以下是消息日志:
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
答案 0 :(得分:1)
根据您显示的错误,我假设您在/app/db.js
的第6行传递给Sequelize的数据库连接字符串未在Heroku上定义,即使它已在您的计算机上定义。
可能的原因可能是你从一个环境变量或你机器上可用但在Heroku实例上不可用的配置文件中获取它。
了解如何在/app/db.js
中初始化Sequelize,其中URL来自哪里,可能会在其中添加一些console.log(YOUR_VARIABLE_NAME)
,然后尝试确保定义它应该如此。
您可以在仪表板中设置Heroku上的环境,这样您就不必在源代码中添加任何凭据,请参阅: