Heroku Nodejs部署错误:应用程序崩溃

时间:2015-07-04 12:29:40

标签: node.js heroku-toolbelt

Log image 这是我的Heroku日志,当我部署我的应用程序时,构建成功但应用程序崩溃了代码503

2015-07-04T12:17:49.485610+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mycityweather.herokuapp.com request_id=37e7fe0c-63fe-4f96-8d17-857df8cfc0c2 fwd="150.129.28.90" dyno= connect= service= status=503 bytes=

2015-07-04T12:17:50.040740+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mycityweather.herok  uapp.com request_id=fc18d77b-8ff5-4a7a-ae4c-5be89d17365b fwd="150.129.28.90" dyno= connect= service= status=503 bytes=

该错误的原因是什么?它的解决方案是什么?

这是我的主要app.js

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var cluster =require("cluster");
var cpusNum=require('os').cpus().length;
var routes = require('./routes/index');
var users = require('./routes/users');


var app = express();
var port=process.env.PORT || 3000;
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);




// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});
if(cluster.isMaster)
{
  //fork Workers
  for(var i=0;i<cpusNum;i++)
  {
    cluster.fork();
  }
    cluster.on('exit',function(worker,code,signal){
    console.log("Worker with "+ worker.process.pid + 'died');
  });
}
else{
    app.listen(port,function(){
    console.log('Server started on port '+port);
    });
}
module.exports = app;

这是我的主要入口点文件,没有正确的错误消息可以告诉我iy的确切原因。

1 个答案:

答案 0 :(得分:1)

知道服务器端和本地计算机上的npm版本有错误。