2017-07-29 8 views
0

herokuで展開した後にnode.jsを使用して自分のWebページを取得できませんでした。私は以下のエラーが発生しています。herokでnode.jsアプリケーションを実行できませんでした

Application error 
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. 

私は以下のログファイルの内容について説明しています。

2017-07-29T12:59:20.918810+00:00 heroku[web.1]: Process exited with status 1 

2017-07-29T13:00:02.740139+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=node-fgdp.herokuapp.com request_id=04e1aa35-0722-4947-a832-836884934abf fwd="223.30.48.118" dyno= connect= service= status=503 bytes= protocol=https 

2017-07-29T13:00:04.519877+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=node-fgdp.herokuapp.com request_id=3ea243cd-db39-43eb-978a-c25c6682e8a0 fwd="223.30.48.118" dyno= connect= service= status=503 bytes= protocol=https 

2017-07-29T13:00:25.971843+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=node-fgdp.herokuapp.com request_id=6df0d3e1-4ccf-442d-a7d4-46951fb2dfd1 fwd="223.30.48.118" dyno= connect= service= status=503 bytes= protocol=https 

2017-07-29T13:00:26.328156+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=node-fgdp.herokuapp.com request_id=e69ce3b6-2b4f-4701-8313-19a5e9152669 fwd="223.30.48.118" dyno= connect= service= status=503 bytes= protocol=https 

2017-07-29T13:06:18.001304+00:00 app[api]: Starting process with command `heroku run` by user [email protected] 

2017-07-29T13:06:19.926935+00:00 heroku[run.9255]: Awaiting client 

2017-07-29T13:06:19.947866+00:00 heroku[run.9255]: Starting process with command `heroku run` 

2017-07-29T13:06:20.133990+00:00 heroku[run.9255]: State changed from starting to up 

2017-07-29T13:06:24.521994+00:00 heroku[run.9255]: Process exited with status 127 

2017-07-29T13:06:24.533168+00:00 heroku[run.9255]: State changed from up to complete 

私はHerokuにコードをデプロイし、生成されたURLを実行すると上記のエラーが発生します。私は以下のコードを説明しています。

package.json:

{ 
    "name": "FGDP", 
    "description": "Our sample Node to Heroku app", 
    "main": "server.js", 
    "scripts": { 
    "start": "node server.js" 
    }, 
    "dependencies": { 
    "express": "~4.14.0", 
    "morgan": "~1.7.0", 
    "body-parser": "~1.15.2", 
    "method-override": "~2.3.7", 
     "mongojs": "~2.4.0", 
    "crypto-js": "~3.1.8", 
    "express-session": "~1.14.2", 
    "multer":"~1.3.0", 
    "dotenv" : "~4.0.0" 
    } 
} 

server.js:

var express=require('express'); 
var morgan = require('morgan'); 
var http=require('http'); 
var bodyParser= require('body-parser'); 
var methodOverride = require('method-override'); 
var mongo = require('mongojs'); 
var session = require('express-session'); 
var multer = require('multer') 
var app=module.exports=express(); 
var server=http.Server(app); 
const dotenv = require('dotenv'); 
dotenv.load(); 
var port=process.env.PORT; 
var admin=require('./route/route.js'); 
app.use(express.static(__dirname + '/public'));  // set the static files location /public/img will be /img for users 
app.use(morgan('dev'));      // log every request to the console 
app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded 
app.use(bodyParser.json()) // parse application/json 
app.use(methodOverride());     // simulate DELETE and PUT 
app.use(session({secret: 'FGDPlexel',resave: true,saveUninitialized: true})); 
app.get('/',function(req,res){ 
    res.sendFile(__dirname + '/index.html'); 
}) 
var storage =multer.diskStorage({ 
    destination: function (req, file, callback) { 
    callback(null, './uploads'); 
    }, 
    filename: function (req, file, callback) { 
    callback(null, file.fieldname + '-' + Date.now()); 
    } 
}); 
app.post('/login',admin.userlogin); 
app.get('/getSessionValue',admin.getSession); 
server.listen(port); 
console.log("Server is running on the port"+port); 

私はdotenvを使用してポートを設定していると、ファイルは以下のとおりです。

.env:

PORT=8989; 

は、ここで私は、アプリケーションを実行する必要があります。

答えて

0

this issueによると、dotenvは生産環境ではHerokuでは動作しません。 Herokuダッシュボードを使用して環境変数を設定します。

+0

設定方法を教えてもらえますか? – satya

+0

ここに行く:https://devcenter.heroku.com/articles/config-vars – tbking

関連する問題