在heroku中部署后,我无法使用node.js获取我的网页。我收到以下错误。
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 subhrajyotipradhan@gmail.com
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
我正在解释下面的日志文件内容。
{
"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"
}
}
我将代码部署到Heroku中,当开始运行生成的URL时,我收到上述错误。我在下面解释我的代码。
的package.json:
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);
server.js:
dotenv
我已使用PORT=8989;
设置端口,文件如下所示。
.ENV:
{{1}}
我需要运行该应用程序。
答案 0 :(得分:1)
不要使用dotenv。您可以从CLI或heroku仪表板中的设置选项卡设置环境变量。在此处阅读更多相关信息:https://devcenter.heroku.com/articles/config-vars#setting-up-config-vars-for-a-deployed-application
答案 1 :(得分:0)
根据this issue,dotenv不会在生产环境中使用Heroku。使用Heroku仪表板设置环境变量。