Node app on Heroku - getting “Application Error”

Greeting, campers!

I have looked through the similar topics and have so far been unable to resolve my deployment issue.

when I’ve deployed it I get an application error. tried to delete it and deploy it again but nothing happened.

https://firetodo.herokuapp.com/

If you are the application owner, check your logs for details.

this is log file:

2018-01-24T11:20:22.865825+00:00 app[web.1]: npm ERR! missing script: start
2018-01-24T11:20:22.873590+00:00 app[web.1]:
2018-01-24T11:20:22.873869+00:00 app[web.1]: npm ERR! A complete log of this run
can be found in:
2018-01-24T11:20:22.873936+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-01-24T11_20_22_867Z-debug.log
2018-01-24T11:20:22.931940+00:00 heroku[web.1]: Process exited with status 1
2018-01-24T11:20:22.945935+00:00 heroku[web.1]: State changed from starting to crashed
2018-01-24T11:20:36.935697+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/" host=firetodo.herokuapp.com request_id=5de4a770-d007-42e6-9450-7edbf746d064 fwd=“197.39.19.110” dyno= connect= service= status=503 bytes= protocol=https
2018-01-24T11:20:38.405704+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/favicon.ico" host=firetodo.herokuapp request_id=611d73af-f491-4ea8-ad41-9625c2e28f5f fwd=“197.39.19.110” dyno= connect= service= status=503 bytes= protocol=https
2018-01-24T11:45:29.690322+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/" host=firetodo.herokuapp request_id=e6977494-b030-48c8-8f79-e95d05711700 fwd=“197.39.19.110” dyno= connect= service= status=503 bytes= protocol=https
2018-01-24T11:45:34.106377+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/favicon.ico" host=firetodo.herokuapp request_id=09d16c24-35ff-4930-a7c2-ff2c0fa15c08 fwd=“197.39.19.110” dyno= connect= service= status=503 bytes= protocol=https
2018-01-24T11:45:41.177551+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=HEAD path="/" host=firetodo.herokuapp request_id=390ba626-8c8c-4909-a3f4-6d8ff21f6a3a fwd=“174.138.37.36” dyno= connect= service= status=503 bytes= protocol=https

You need a start script in your package.json file. Something like:

"scripts": {
    "start": "node server.js"
}

now I’m getting this

2018-01-24T12:02:14.220261+00:00 app[web.1]: npm ERR! Exit status 1
2018-01-24T12:02:14.221027+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-01-24T12:02:14.220561+00:00 app[web.1]: npm ERR!
2018-01-24T12:02:14.220766+00:00 app[web.1]: npm ERR! Failed at the to-do-app@1.0.0 start script.
2018-01-24T12:02:14.234884+00:00 app[web.1]:
2018-01-24T12:02:14.235228+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-01-24T12:02:14.235401+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-01-24T12_02_14_222Z-debug.log
2018-01-24T12:02:14.303238+00:00 heroku[web.1]: Process exited with status 1
2018-01-24T12:02:14.312646+00:00 heroku[web.1]: State changed from starting to crashed
2018-01-24T12:02:20.609095+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/" host=firetodo.herokuapp.com request_id=968b7a24-2faf-4378-b8ba-9749ec3ee2ea fwd=“197.39.19.110” dyno= connect= service= status=503 bytes= protocol=https
2018-01-24T12:02:21.884234+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/favicon.ico" host=firetodo.herokuapp.com request_id=b30b00c4-aca3-4edc-9105-a46bd3757343 fwd=“197.39.19.110” dyno= connect= service= status=503 bytes= protocol=https

Does it work locally when you run npm start? And what does your package.json look like now?

Yes, it works locally, and this is my package.json content:

{
“name”: “to-do-app”,
“version”: “1.0.0”,
“description”: “Simple To-Do App”,
“main”: “app.js”,
“scripts”: {
“start”: “node server.js”
},
“author”: “wael”,
“license”: “ISC”,
“dependencies”: {
“body-parser”: “^1.18.2”,
“ejs”: “^2.5.7”,
“express”: “^4.16.2”,
“mongoose”: “^5.0.1”
}
}

If you named your main file app.js, you should also use node app.js inside the start script.

1 Like

Good we are getting close to solve it, now I’m getting this:

2018-01-24T12:19:06.563946+00:00 heroku[web.1]: State changed from crashed to starting
2018-01-24T12:19:09.001583+00:00 heroku[web.1]: Starting process with command npm start
2018-01-24T12:19:11.473433+00:00 app[web.1]:
2018-01-24T12:19:11.473449+00:00 app[web.1]: > to-do-app@1.0.0 start /app
2018-01-24T12:19:11.473451+00:00 app[web.1]: > node app.js
2018-01-24T12:19:11.473452+00:00 app[web.1]:
2018-01-24T12:19:12.385281+00:00 heroku[web.1]: State changed from starting to up
2018-01-24T12:19:12.291926+00:00 app[web.1]: Express server listening on port 3900 in production mode
2018-01-24T12:19:13.578005+00:00 heroku[router]: at=info method=GET path="/" host=firetodo.herokuapp.com request_id=bb55228c-ca57-4e30-bf87-be53aa1a6d8c fwd=“197.39.19.110” dyno=web.1 connect=0ms service=60ms status=404 bytes=383 protocol=https
2018-01-24T12:19:14.885440+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=firetodo.herokuapp.com request_id=64b16bb7-8a7f-4583-ab4c-0a4243c2445a fwd=“197.39.19.110” dyno=web.1 connect=0ms service=4ms status=404 bytes=394 protocol=https
2018-01-24T12:19:15.873746+00:00 heroku[router]: at=info method=GET path="/" host=firetodo.herokuapp request_id=7071c9eb-d275-48d6-ba1c-46d6fb0604ef fwd=“197.39.19.110” dyno=web.1 connect=0ms service=10ms status=404 bytes=383 protocol=https

Well, it is working then, right?

no now it says: "Cannot GET / " when I go to the app link

https://firetodo.herokuapp.com/

I would have to see the code, do you have it on GitHub or somewhere online?

You don’t specify what to do on specific routes. You only use ./public as static folder and set ejs as view engine.

And that is working. Try going to /assets/logo.png (a file in your static folder) or to /todo (a view).

I can’t understand what should I do now? Can you explain more?

You only have this get route: app.get('/todo', function(req, res). So only when you go to /todo your express server will actually do something. If you want to always render the todo view you can use: app.get('*', function(req, res)

Or if you only want / and /todo to render the todo view, you can add this route:

app.get('/', function(req, res){
   res.redirect('/todo');
});
2 Likes

Oh my god it worked !!! thank you very much for your tips

2 Likes

my heroku bot wasnt working. this is whats its end up.

Application Logs

2020-01-25T06:44:23.822533+00:00 app[web.1]: npm ERR! errno 1

2020-01-25T06:44:23.823548+00:00 app[web.1]: npm ERR! bot096@1.0.0 start: `node index.js`

2020-01-25T06:44:23.823682+00:00 app[web.1]: npm ERR! Exit status 1

2020-01-25T06:44:23.823870+00:00 app[web.1]: npm ERR! 

2020-01-25T06:44:23.824012+00:00 app[web.1]: npm ERR! Failed at the bot096@1.0.0 start script.

2020-01-25T06:44:23.824090+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

2020-01-25T06:44:23.832177+00:00 app[web.1]: 

2020-01-25T06:44:23.832315+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:

2020-01-25T06:44:23.832411+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-01-25T06_44_23_824Z-debug.log

2020-01-25T06:44:23.898784+00:00 heroku[web.1]: Process exited with status 1

2020-01-25T06:44:41.187627+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=bot096.herokuapp.com request_id=efe995cb-eeaa-4d07-8439-3f47fcc8c124 fwd="150.107.175.152" dyno= connect= service= status=503 bytes= protocol=https

2020-01-25T06:45:10.853502+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=bot096.herokuapp.com request_id=023561bb-2e6a-402b-931a-2ad82de2d2d5 fwd="150.107.175.152" dyno= connect= service= status=503 bytes= protocol=https

2020-01-25T06:45:11.507769+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=bot096.herokuapp.com request_id=593e5e66-0c70-4ebd-b423-f14c3f94b298 fwd="150.107.175.152" dyno= connect= service= status=503 bytes= protocol=https```
  1. Include a Server.js File on the root directory of your project

  2. Copy and paste
    var express = require('express')
    var path = require('path')
    var serveStatic = require('serve-static')

    var app = express()
    app.use(serveStatic(path.join(__dirname, 'dist')))

    var port = process.env.PORT || 8000
    app.listen(port)
    console.log('server started ' + port)

  3. Add this to your script "start": "node server.js",

  4. Push to heroku

please I am still facing the same challenge

please I need help.

Every time I try to deploy either my database or my server I still get this response. Please help.