【问题标题】:Node.js app on Heroku returns "Process exited with status 127" in logsHeroku 上的 Node.js 应用程序在日志中返回“进程退出,状态为 127”
【发布时间】:2019-07-24 15:45:55
【问题描述】:

在 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 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

我将我的代码部署到 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;

在这里我需要运行应用程序。

【问题讨论】:

    标签: node.js heroku


    【解决方案1】:

    不要使用 dotenv。您可以从 CLI 或 heroku 仪表板中的设置选项卡设置环境变量。在此处阅读更多信息:https://devcenter.heroku.com/articles/config-vars#setting-up-config-vars-for-a-deployed-application

    【讨论】:

      【解决方案2】:

      根据this issue dotenv 不适用于生产环境中的 Heroku。使用 Heroku 仪表板设置环境变量。

      【讨论】:

      • 你能帮我怎么设置吗?
      猜你喜欢
      • 2015-04-24
      • 1970-01-01
      • 2018-09-09
      • 2017-09-28
      • 1970-01-01
      • 2017-12-13
      • 2019-02-26
      • 2020-10-18
      • 1970-01-01
      相关资源
      最近更新 更多