【发布时间】:2016-08-27 22:36:54
【问题描述】:
我是 Node.js 和 Heroku 的新手,正在尝试在 Heroku 上托管我的第一个应用程序,但在部署时遇到了问题。我一直在按照本教程部署应用程序:https://scotch.io/tutorials/use-mongodb-with-a-node-application-on-heroku
在 cmd 提示符下,我执行了以下操作:
1.heroku
2.heroku登录
3. heroku 创建应用
4. git push heroku master
5. heroku ps:scale web=1
6.heroku 打开
7. heroku logs --tail(下面是heroku打开后我看到的日志信息列表)
在我的 mLab 控制台上,我创建了一个数据库、集合和用户,并将我的 mongo URI 定义如下:
'mongodb://admin:********@asdf1234.mlab.com:13122/app'
如果我在本地启动我的 Node 应用程序,我可以成功地在这个数据库中创建数据,但是当我尝试从 Heroku 访问我的应用程序时,我得到了应用程序错误网页。我知道我一定是在某个地方遗漏了一个步骤?我相信这与猫鼬有关?
2016-05-03T02:27:29.458496+00:00 heroku[web.1]: State changed from crashed to starting
2016-05-03T02:27:33.077531+00:00 heroku[web.1]: Starting process with command `npm start`
2016-05-03T02:27:35.383818+00:00 app[web.1]:
2016-05-03T02:27:35.383872+00:00 app[web.1]: > app@0.0.0 start /app
2016-05-03T02:27:35.383878+00:00 app[web.1]: > node ./bin/www
2016-05-03T02:27:35.383887+00:00 app[web.1]:
2016-05-03T02:27:35.587955+00:00 app[web.1]: { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
2016-05-03T02:27:35.589136+00:00 app[web.1]: js-bson: Failed to load c++ bson extension, using pure JS version
2016-05-03T02:27:35.947930+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2016-05-03T02:27:35.947945+00:00 app[web.1]: designed for a production environment, as it will leak
2016-05-03T02:27:35.947946+00:00 app[web.1]: memory, and will not scale past a single process.
2016-05-03T02:27:35.986323+00:00 app[web.1]:
2016-05-03T02:27:35.986338+00:00 app[web.1]: /app/node_modules/mongoose/node_modules/mongodb/lib/server.js:242
2016-05-03T02:27:35.986339+00:00 app[web.1]: process.nextTick(function() { throw err; })
2016-05-03T02:27:35.986341+00:00 app[web.1]: ^
2016-05-03T02:27:35.986344+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:27017
2016-05-03T02:27:35.986345+00:00 app[web.1]: at Object.exports._errnoException (util.js:893:11)
2016-05-03T02:27:35.986346+00:00 app[web.1]: at exports._exceptionWithHostPort (util.js:916:20)
2016-05-03T02:27:35.986347+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1075:14)
2016-05-03T02:27:35.997520+00:00 app[web.1]:
2016-05-03T02:27:36.009323+00:00 app[web.1]: npm ERR! Linux 3.13.0-79-generic
2016-05-03T02:27:36.009834+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-05-03T02:27:36.010139+00:00 app[web.1]: npm ERR! node v5.11.0
2016-05-03T02:27:36.010913+00:00 app[web.1]: npm ERR! npm v3.8.6
2016-05-03T02:27:36.011252+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-05-03T02:27:36.011483+00:00 app[web.1]: npm ERR! app@0.0.0 start: `node ./bin/www`
2016-05-03T02:27:36.011697+00:00 app[web.1]: npm ERR! Exit status 1
2016-05-03T02:27:36.011937+00:00 app[web.1]: npm ERR!
2016-05-03T02:27:36.012344+00:00 app[web.1]: npm ERR! Failed at the app@0.0.0 start script 'node ./bin/www'.
2016-05-03T02:27:36.012587+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-05-03T02:27:36.012830+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the app package,
2016-05-03T02:27:36.013080+00:00 app[web.1]: npm ERR! not with npm itself.
2016-05-03T02:27:36.013296+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-05-03T02:27:36.013522+00:00 app[web.1]: npm ERR! node ./bin/www
2016-05-03T02:27:36.013730+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-05-03T02:27:36.013943+00:00 app[web.1]: npm ERR! npm bugs app
2016-05-03T02:27:36.014152+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-05-03T02:27:36.014360+00:00 app[web.1]: npm ERR! npm owner ls app
2016-05-03T02:27:36.014579+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-05-03T02:27:36.021124+00:00 app[web.1]:
2016-05-03T02:27:36.021429+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-05-03T02:27:36.021644+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2016-05-03T02:27:36.772785+00:00 heroku[web.1]: Process exited with status 1
2016-05-03T02:27:36.779023+00:00 heroku[web.1]: State changed from starting to crashed
如果有帮助,我的 package.json 文件如下所示:
{
"name": "app",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "~1.13.2",
"connect-flash": "^0.1.1",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"express-session": "^1.13.0",
"jade": "~1.11.0",
"mongodb": "~1.4.4",
"mongoose": "^4.4.6",
"monk": "~1.0.1",
"morgan": "~1.6.1",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"serve-favicon": "~2.3.0"
}
}
感谢您的帮助!
编辑:
我所缺少的只是我的 package.json 中的节点版本,以下为我修复了它:
"engines": {
"node": "4.3.2"
},
【问题讨论】:
标签: javascript node.js mongodb heroku mongoose