Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku is giving me a 503 when trying to open my web app, works on local host

Tags:

I am trying to deploy to heroku but get a 503 even though it runs on localhost. I am curious as to if my server is set up correctly as I am newer to programming. I hope anyone can point me in the correct direction as to where to look or provide a suggestion as I have spent countless hours on google to this point spanning a couple of weeks.

My main question is if I have set up my server correctly? I am not sure my listener will work for heroku and my .get are used for debugging on localhost when it was initially set up.

Also my full project is available here:

https://github.com/dirkdir/DerekDevSite

var express = require('express'); var app = express(); var path = require('path');   app.use(express.static(path.join(__dirname, 'public')));   app.get('/json', function(req, res) {     console.log("GET the json");     res         .status(200)         .json( {"jsonData" : true} ); });  app.get('/file', function(req, res) {     console.log("GET the file");     res         .status(200)         .sendFile(path.join(__dirname, 'app.js')); });        var server = app.listen(process.env.PORT || 5000), function() {         var port = server.address().port;         console.log("Express is working on port " + port); }); 

Logs:

2017-04-24T20:04:43.755866+00:00 app[web.1]: at Module._compile (module.js:542:28) 2017-04-24T20:04:43.755867+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10) 2017-04-24T20:04:43.755868+00:00 app[web.1]: at Module.load (module.js:487:32) 2017-04-24T20:04:43.755868+00:00 app[web.1]: at tryModuleLoad (module.js:446:12) 2017-04-24T20:04:43.755869+00:00 app[web.1]: at Function.Module._load (module.js:438:3) 2017-04-24T20:04:43.755869+00:00 app[web.1]: at Module.runMain (module.js:604:10) 2017-04-24T20:04:43.755870+00:00 app[web.1]: at run (bootstrap_node.js:393:7) 2017-04-24T20:04:43.755871+00:00 app[web.1]: at startup (bootstrap_node.js:150:9) 2017-04-24T20:04:43.846556+00:00 heroku[web.1]: State changed from starting to crashed 2017-04-24T20:26:31.826133+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=derekdyerdev.herokuapp.com request_id=609ef253-0a56-41ac-b877-1fb242f6f4e1 fwd="69.36.89.218" dyno= connect= service= status=503 bytes= protocol=https 2017-04-24T20:26:32.319732+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=derekdyerdev.herokuapp.com request_id=f2a34e62-9765-

like image 829
Derek Dyer Avatar asked Apr 24 '17 20:04

Derek Dyer


People also ask

Can Heroku use localhost?

Start your app locally using the heroku local command, which is installed as part of the Heroku CLI. Your app should now be running on http://localhost:5000/.

Why Heroku shows application Error?

"Application Error" or similar is always caused by your own application code. Routing errors will normally only surface themselves within the logs of your application. In most cases, you will be able to see the cause of the error there. To learn more about logging, please see our Logging article on DevCenter.

What is a 503 status code?

The HyperText Transfer Protocol (HTTP) 503 Service Unavailable server error response code indicates that the server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded.


1 Answers

You have the bracket on line 34 of your app.js file in the wrong place. Since the function is a callback, it needs to be within the params.

Change that last block to this:

const server = app.listen(process.env.PORT || 5000, () => {   const port = server.address().port;   console.log(`Express is working on port ${port}`); }); 

I also modified the Procfile to just this:

web: node app.js 

After I modified that I was able to run locally, and I deployed it to my Heroku just to test, and it works fine :)

like image 59
Alicia Avatar answered Sep 18 '22 11:09

Alicia