javascript - Heroku Node.js 应用程序 "Process exited with status 1"和错误 h10

标签 javascript node.js heroku

我将我的应用程序部署到heroku,没有任何问题。我能够在 localhost:5000 上运行 heroku local web 并且它有效。当我访问 web dyno 地址时,它说应用程序错误。我检查了该网站的日志,上面写着:

 2017-05-01T02:52:30.980217+00:00 app[web.1]:     at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:274:12)
 2017-05-01T02:52:30.980218+00:00 app[web.1]:     at emitTwo (events.js:106:13)
 2017-05-01T02:52:30.980218+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:177:49)
 2017-05-01T02:52:30.980218+00:00 app[web.1]:     at Connection.emit (events.js:191:7)
 2017-05-01T02:52:30.980219+00:00 app[web.1]:     at emitOne (events.js:96:13)
 2017-05-01T02:52:30.980220+00:00 app[web.1]:     at Socket.emit (events.js:188:7)
 2017-05-01T02:52:30.980221+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:104:9)
 2017-05-01T02:52:31.040828+00:00 heroku[web.1]: State changed from starting to crashed
 2017-05-01T02:52:31.029211+00:00 heroku[web.1]: Process exited with status 1
 2017-05-01T02:52:40.638415+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=room111-thoughts.herokuapp.com request_id=91b591cf-3d8d-4d94-8caf-7b1b868b088b fwd="108.221.62.78" dyno= connect= service= status=503 bytes= protocol=https
 2017-05-01T02:52:41.600924+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=room111-thoughts.herokuapp.com request_id=c8f6c2d3-dc38-4e65-9a20-581910f42b36 fwd="108.221.62.78" dyno= connect= service= status=503 bytes= protocol=https

我使用的是node.js和server.js(初始化脚本)如下

// load environment variables
require('dotenv').config();

// grab our dependencies
const express    = require('express'),
  app            = express(),
  port           = process.env.PORT || 8080,
  expressLayouts = require('express-ejs-layouts'),
  mongoose       = require('mongoose'),
  bodyParser     = require('body-parser'),
  session        = require('express-session'),
  cookieParser   = require('cookie-parser'),
  flash          = require('connect-flash'),
  expressValidator = require('express-validator');

// configure our application ===================
// set sessions and cookie parser
app.use(cookieParser());
app.use(session({
  secret: process.env.SECRET, 
  cookie: { maxAge: 60000 },
  resave: false,    // forces the session to be saved back to the store
  saveUninitialized: false  // dont save unmodified
}));
app.use(flash());

// tell express where to look for static assets
app.use(express.static(__dirname + '/public'));

// set ejs as our templating engine
app.set('view engine', 'ejs');
app.use(expressLayouts);

// connect to our database
mongoose.connect(process.env.DB_URI);

// use body parser to grab info from a form
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressValidator());

// set the routes =============================
app.use(require('./app/routes'));

// start our server ===========================
app.listen(port, () => {
  console.log(`App listening on http://localhost:${port}`);
});

我不知道发生了什么,特别是因为它在本地主机和部署上运行良好。如有任何帮助,我们将不胜感激。

最佳答案

我遇到了完全相同的问题。我没有使用 mongo db 但错误是相同的:

2018-01-23T09:30:10.806568+00:00 heroku[web.1]: Process exited with status 1
2018-01-23T09:30:10.823360+00:00 heroku[web.1]: State changed from starting to crashed
2018-01-23T09:30:32.001596+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/"....

该应用程序在本地主机上完美运行,但在部署到 Heroku 上时崩溃了。 Heroku 网站日志页面根本没有帮助,所以我通过命令行在本地尝试:heroku log --tail 并显示了网站中未显示的许多日志。这些日志说:

2018-01-23T09:30:09.431324+00:00 heroku[web.1]: Starting process with command `node server.js`
2018-01-23T09:30:10.771449+00:00 app[web.1]: module.js:540
2018-01-23T09:30:10.771465+00:00 app[web.1]:     throw err;
2018-01-23T09:30:10.771466+00:00 app[web.1]:     ^
2018-01-23T09:30:10.771468+00:00 app[web.1]:
2018-01-23T09:30:10.771470+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:538:15)
2018-01-23T09:30:10.771469+00:00 app[web.1]: Error: Cannot find module 'express'

我意识到我必须安装express,所以我运行:

npm install express
git push heroku master
heroku open 

并且成功了。 希望它也对您有用!!

关于javascript - Heroku Node.js 应用程序 "Process exited with status 1"和错误 h10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43713758/

相关文章:

javascript - 哪些组件正在添加情感 css 全局样式

node.js - Sequelize 保存多对多

python - 模块未找到错误 : No module named 'django' in Heroku

git - 使用 bitbucket 管道部署到 heroku 到非 master 分支

ruby-on-rails - Rails 3.2 重定向/images/* 到/assets/*

javascript - 编写此 .map 调用的更优雅的方式?

javascript - window.location 下载具有大请求数据的文件

javascript - 将 Java List<String> 转换为 Javascript 数组

node.js - 我正在使用 typescript 编译一个 node.js 项目,但我不确定如何运行单个脚本

javascript - 高级原型(prototype)函数