You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署至Heroku时应用崩溃(错误码H10)求助

Fixing Heroku H10 App Crash for Your Burger App

Hey there, let's work through why your app keeps crashing on Heroku with that H10 error. Let's break down the issues step by step:

First: The Obvious Typo Breaking Your Server Startup

Looking straight at your app.js code, there's a case-sensitive variable mistake that's almost certainly causing the immediate crash:
You defined your port variable as uppercase:

var PORT = process.env.PORT || 3000;

But then you tried to listen on a lowercase port variable that doesn't exist at all:

app.listen(port, "0.0.0.0", function () {
  console.log("Listening on Port 3000");
});

Fix This Right Away:

Update that listen line to use the correct uppercase PORT variable, and make the log dynamic to show the actual port Heroku assigns (it won't always be 3000):

app.listen(PORT, "0.0.0.0", function () {
  console.log(`Listening on Port ${PORT}`);
});

Next: Check for Other Potential Crash Causes

Even after fixing the typo, there might be hidden issues. Here's what to verify next:

1. Test Your App Locally First

Run npm start on your local machine. If it crashes here, you'll get direct, clear error messages—like missing controller files, failed database connections, or broken require statements—that will tell you exactly what's broken. Don't deploy to Heroku until your app runs flawlessly locally.

2. Get Detailed Heroku Error Logs

The router logs you shared only tell you the app crashed, not why. Run this command in your CLI to see real-time startup errors:

heroku logs --tail

This will show you if there's a missing dependency, a typo in your controller path, or a database connection failure that's killing the app before it can start.

3. Database Configuration Issues

You've got both mysql and mongodb in your dependencies, but Heroku doesn't provide a free local database by default:

  • For MySQL: Add the ClearDB MySQL add-on to your Heroku app, then use the environment variables provided by ClearDB to configure your database connection (never hardcode local DB credentials).
  • For MongoDB: Use a service like MongoDB Atlas or the Heroku MongoDB add-on, and make sure your connection string is set as an environment variable on Heroku.

4. Double-Check Your package.json

Your package.json looks mostly solid, but confirm:

  • The start script is correctly set to node app.js (it is, good call!)
  • All listed dependencies are actually used in your app, and you've run npm install locally before deploying (Heroku will install them automatically, but local mismatches can cause deployment failures)

Your Original Error Logs:

2019-06-19T12:32:14.679424+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=guarded-island-18465.herokuapp.com request_id=66a60c63-3bad-47ad-8255-85f56798df95fwd="97.99.40.66" dyno= connect= service= status=503 bytes= protocol=https
2019-06-19T12:32:15.283697+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=guarded-island-18465.herokuapp.com request_id=888cb97b-7aaf-4e0b-97c5-d01432d188a6 fwd="97.99.40.66" dyno= connect= service= status=503 bytes= protocol=https

Your package.json:

{ 
  "name": "newburger2", 
  "version": "1.0.0", 
  "description": "", 
  "main": "app.js", 
  "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1", 
    "start": "node app.js" 
  }, 
  "repository": { 
    "type": "git", 
    "url": "git+https://github.com/jnperk1234/neweatdaburger.git" 
  }, 
  "author": "", 
  "license": "ISC", 
  "bugs": { 
    "url": "https://github.com/jnperk1234/neweatdaburger/issues" 
  }, 
  "homepage": "https://github.com/jnperk1234/neweatdaburger#readme", 
  "dependencies": { 
    "body-parser": "^1.19.0", 
    "express": "^4.17.1", 
    "express-handlebars": "^3.1.0", 
    "mongodb": "^3.2.6", 
    "mysql": "^2.17.1" 
  } 
}

Your Original app.js:

var express = require("express"); 
var bodyParser = require("body-parser"); 
var exphbs = require("express-handlebars"); 
var app = express(); 
var PORT = process.env.PORT || 3000; 
app.use(express.static("public")); 
app.use(bodyParser.urlencoded({ extended: true })); 
app.use(bodyParser.json()); 
app.engine("handlebars", exphbs({ defaultLayout: "main" })); 
app.set("view engine", "handlebars"); 
var routes = require("./controllers/burgers_controller.js"); 
app.use(routes); 
app.listen(port, "0.0.0.0", function () { 
  console.log("Listening on Port 3000"); 
});

内容的提问来源于stack exchange,提问作者Jessica Perkins

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:36:35