Node.js 将nodejs部署到Heroku时抛出错误URL

Node.js 将nodejs部署到Heroku时抛出错误URL,node.js,heroku,sequelize.js,Node.js,Heroku,Sequelize.js,我有一个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]: > nod

我有一个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
2017-01-13T04:16:32.949664+00:00应用程序[web.1]:>golaundryserver@1.0.0启动/应用程序
2017-01-13T04:16:32.949665+00:00应用程序[web.1]:>node server.js
2017-01-13T04:16:32.949665+00:00应用程序[网站1]:
2017-01-13T04:16:33.344617+00:00应用程序[网站1]:url.js:87
2017-01-13T04:16:33.344629+00:00应用程序[web.1]:抛出新类型错误('参数“url”必须是字符串,而不是'+typeof url');
2017-01-13T04:16:33.344630+00:00应用程序[网站1]:^
2017-01-13T04:16:33.344631+00:00应用程序[网站1]:
2017-01-13T04:16:33.344633+00:00应用程序[web.1]:类型错误:参数“url”必须是字符串,而不是未定义的
2017-01-13T04:16:33.344634+00:00应用程序[web.1]:位于Url.parse(Url.js:87:11)
2017-01-13T04:16:33.344636+00:00应用程序[web.1]:在Object.urlParse[as parse](url.js:81:5)
2017-01-13T04:16:33.344636+00:00应用程序[web.1]:在新的Sequelize(/app/node_modules/Sequelize/lib/Sequelize.js:125:24)
2017-01-13T04:16:33.344637+00:00应用程序[web.1]:at对象。(/app/db.js:6:17)
2017-01-13T04:16:33.344638+00:00应用程序[web.1]:at模块编译(模块js:570:32)
2017-01-13T04:16:33.344638+00:00应用程序[web.1]:at Object.Module.\u extensions..js(Module.js:579:10)
2017-01-13T04:16:33.344639+00:00应用程序[web.1]:at Module.load(Module.js:487:32)
2017-01-13T04:16:33.344640+00:00应用程序[web.1]:在tryModuleLoad(module.js:446:12)
2017-01-13T04:16:33.344640+00:00应用程序[web.1]:在功能模块加载时(模块js:438:3)
2017-01-13T04:16:33.344641+00:00应用程序[web.1]:位于Module.require(Module.js:497:17)
2017-01-13T04:16:33.344642+00:00应用程序[web.1]:根据需要(内部/模块js:20:19)
2017-01-13T04:16:33.344642+00:00应用程序[web.1]:at对象。(/app/server.js:1:72)
2017-01-13T04:16:33.344643+00:00应用程序[web.1]:at模块编译(模块js:570:32)
2017-01-13T04:16:33.344643+00:00应用程序[web.1]:at Object.Module.\u extensions..js(Module.js:579:10)
2017-01-13T04:16:33.344644+00:00应用程序[web.1]:at Module.load(Module.js:487:32)
2017-01-13T04:16:33.344645+00:00应用程序[web.1]:在tryModuleLoad(module.js:446:12)
2017-01-13T04:16:33.353999+00:00应用程序[网站1]:
2017-01-13T04:16:33.362350+00:00应用程序[网站1]:npm错误!Linux 3.13.0-105-generic
2017-01-13T04:16:33.362417+00:00应用程序[网站1]:npm错误!argv“/app/.heroku/node/bin/node”“/app/.heroku/node/bin/npm”“开始”
2017-01-13T04:16:33.362573+00:00应用程序[网站1]:npm错误!节点v6.9.4
2017-01-13T04:16:33.362726+00:00应用程序[网站1]:npm错误!npm v4.1.1
2017-01-13T04:16:33.362920+00:00应用程序[网站1]:npm错误!代码失效循环
2017-01-13T04:16:33.363075+00:00应用程序[网站1]:npm错误!golaundryserver@1.0.0start:`node server.js`
2017-01-13T04:16:33.363192+00:00应用程序[网站1]:npm错误!退出状态1
2017-01-13T04:16:33.363477+00:00应用程序[网站1]:npm错误!
2017-01-13T04:16:33.363609+00:00应用程序[网站1]:npm错误!失败golaundryserver@1.0.0启动脚本“node server.js”。
2017-01-13T04:16:33.363736+00:00应用程序[网站1]:npm错误!确保已安装最新版本的node.js和npm。
2017-01-13T04:16:33.363916+00:00应用程序[网站1]:npm错误!如果是这样,这很可能是golaundryserver包的问题,
2017-01-13T04:16:33.364086+00:00应用程序[网站1]:npm错误!与npm本身无关。
2017-01-13T04:16:33.364367+00:00应用程序[网站1]:npm错误!告诉作者此操作在您的系统上失败:
2017-01-13T04:16:33.364662+00:00应用程序[网站1]:npm错误!node server.js
2017-01-13T04:16:33.365384+00:00应用程序[网站1]:npm错误!您可以通过以下方式获取有关如何打开此项目问题的信息:
2017-01-13T04:16:33.365555+00:00应用程序[网站1]:npm错误!npm bugs服务器
2017-01-13T04:16:33.365732+00:00应用程序[网站1]:npm错误!或者,如果不可用,您可以通过以下方式获取他们的信息:
2017-01-13T04:16:33.365933+00:00应用程序[网站1]:npm错误!npm所有者ls golaundryserver
2017-01-13T04:16:33.366104+00:00应用程序[网站1]:npm错误!上面可能还有其他日志输出。
2017-01-13T04:16:33.370608+00:00应用程序[网站1]:
2017-01-13T04:16:33.370806+00:00应用程序[网站1]:npm错误!请在任何支持请求中包括以下文件:
2017-01-13T04:16:33.370908+00:00应用程序[网站1]:npm错误/app/npm-debug.log
2017-01-13T04:16:33.450002+00:00 heroku[web.1]:进程退出,状态为1
2017-01-13T04:16:33.423935+00:00 heroku[web.1]:状态从开始更改为崩溃

根据您显示的错误,我的假设是,您在
/app/db.js
的第6行中传递给Sequelize的数据库连接字符串没有在Heroku上定义,即使它是在您的计算机上定义的

可能的原因是,您可以从环境变量或某些配置文件获得它,这些配置文件在您的计算机上可用,但在Heroku实例上不可用

查看Sequelize是如何在URL的来源
/app/db.js
中初始化的,可以在那里添加一些
console.log(您的变量名)
,然后尝试确保它的定义是正确的

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


非常感谢,我意识到我在连接DB时的代码有一些错误。