server.js文件:
var port = Number(process.env.PORT || 3000);
var express = require('express');
var app = require('./app');
var debug = require('debug')('myapp:server');
var http = require('http');
app.set('port', port);
var server = http.createServer(app);
server.listen(port);
db.js
var mongoose = require('mongoose');
exports.connnect = function(){
mongoose.connect(process.env.MONGOLAB_URI);
console.log("Connected Successfully--!");
}
的package.json
{
"name": "myapp",
"version": "0.0.0",
"private": true,
"main": "server.js",
"readme": "README.md",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "~1.15.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
"express-session": "^1.14.0",
"jade": "~1.11.0",
"mongoose": "^4.5.4",
"morgan": "~1.7.0",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"pug": "^2.0.0-beta3",
"serve-favicon": "~2.3.0"
},
"engines" :{
"node": "4.4.5",
"npm": "3.10.5"
}
}
我的Procfile文件
web: node server.js
我收录了README.md
个文件,所有包裹都是
但每当我在构建之后将项目推送到github时,它就显示出来了:
2016-07-17T09:43:46.021568+00:00 app[web.1]: npm ERR! npm bugs myapp
2016-07-17T09:43:46.021700+00:00 app[web.1]: npm ERR! npm owner ls myapp
2016-07-17T09:43:46.021811+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-07-17T09:43:46.026030+00:00 app[web.1]:
2016-07-17T09:43:46.026324+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2016-07-17T09:43:46.912101+00:00 heroku[web.1]: Process exited with status 1
2016-07-17T09:43:46.926177+00:00 heroku[web.1]: State changed from starting to crashed
当我在浏览器中指向新页面时执行命令npm bugs myapp
时显示:
但每当我试图运行我的应用程序显示错误,如
at=error code=H10 desc="App crashed" method=GET path="/" host=aqueous-harbor-57127.herokuapp.com request_id=13794f33-cebe-46bc-8222-f908466bc7e2 fwd="103.15.60.210" dyno= connect= service= status=503 bytes=
2016-07-17T10:21:13.984164+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=aqueous-harbor-57127.herokuapp.com request_id=ae23dbea-9894-4bdd-ab9d-3bcd5d202fb5 fwd="103.15.60.210" dyno= connect= service= status=503 bytes=
我不知道该怎么做;该应用程序在我的本地系统上完美运行,但我不知道为什么这会导致Heroku出错。
答案 0 :(得分:0)
您应该在上面显示更多日志:
npm ERR! npm bugs myapp
这一行:
at=error code=H10 desc="App crashed" method=GET path="/" host=aqueous-harbor-57127.herokuapp.com request_id=13794f33-cebe-46bc-8222-f908466bc7e2 fwd="103.15.60.210" dyno= connect= service= status=503 bytes=
基本上是说你的应用程序崩溃并返回503 在你的例子中没有太多可能失败,所以我会尝试猜测:
process.env.MONGOLAB_URI
您是否正确为您的heroku应用设置了env?
https://devcenter.heroku.com/articles/getting-started-with-nodejs#define-config-vars