2017-07-29 68 views
0

在heroku中部署後,我無法使用node.js獲取我的網頁。我收到下面的錯誤。無法在Heroku上運行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

相關問題