0
votes

I'm trying to deploy my app to Heroku and I keep crashing. I use my CLI to open up my app and it still crash and I even deploy the branches on the Keroku dashboard and it still crashes. I was wondering what's wrong with my app.js or packjson

This is the error I get:

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=https2019-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

{
  "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"
  }
}

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");
});
3

3 Answers

1
votes

This helped me. The default buildpack when deploying is that of node.js. You needed to use the create-react-app buildpack (as seen below).

heroku create $APP_NAME --buildpack mars/create-react-app
git push heroku master
heroku open
0
votes

I can see that you declared the PORT variable in capital letters. However, in the final line, it is used in small letters. Try changing it to be:

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

As it is, a ReferenceError will be thrown by Express which would then crash the server on Heroku.