2016-07-17 25 views
0

server.js文件:無法在Heroku上運行我的第一平均應用

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當我被引導到瀏覽器中的新頁面顯示:Error description Page

但是,每當我試圖運行我的應用程序顯示錯誤,如

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出現錯誤。

https://aqueous-harbor-57127.herokuapp.com/

回答

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

相關問題