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

53,408

Solution 1

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 :)

Solution 2

This may be helpful to someone. My initial Profile content was this :

web : node server.js

and after changing it to this, it worked :

web:node server.js

The space between 'web' and ':' symbol was the problem. Weird though

Solution 3

I had a similar issue. Worked on localhost.. not when deployed to Heroku. My problem? I had cloned a project (node_modules too) and my package.json did not have express, minimist etc.. so it obviously failed.

Tip: When deploying, view the logs right away so you can see what's happening throughout the deployment process. Viewing the logs after it has failed will only show you the end of the logs...

Lastly, ensure you listen on the proper port. I do this (as others do too)

var serverPort = 8080;
. . .
var port = process.env.PORT || serverPort;

Solution 4

I was struggling with similar problem then noticed quotation marks in my Procfile. When I removed them problem solved.

 "web: node index.js" WRONG!

It must be without quotes:

 web: node index.js CORRECT!

Solution 5

This Might help others

  1. From Terminal Check out your Heroku Logs
  2. Check out the error message
  3. This might be possible that any npm module you have installed globally
  4. Then just install that npm module locally.
  5. Commit the updated package.json and package-lock.json file on git.
  6. Then run git push Heroku master.
Share:
53,408

Related videos on Youtube

Derek Dyer
Author by

Derek Dyer

Updated on October 16, 2021

Comments

  • Derek Dyer
    Derek Dyer over 2 years

    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-

    • Ananth Rao
      Ananth Rao about 7 years
      look at/share your heroku logs. then you'll have more insight to what the problem might be
    • Lissy93
      Lissy93 about 7 years
      Can you run heroku logs --tail and paste the result here? (this will return recently logged errors, and will probably indicate what is going wrong)
    • Derek Dyer
      Derek Dyer about 7 years
      Lissy, thank you for your response. I am currently in the office and cannot run the above command, however, I have posted my logs in the question body at the bottom
  • Lissy93
    Lissy93 about 7 years
    Here's a demo of it on my Heroku: nameless-beach-38136.herokuapp.com (don't worry, I'm taking it down as soon as you've seen it!) It's looking good though!
  • Derek Dyer
    Derek Dyer about 7 years
    Thank you so much! That is awesome. I really appreciate your help! It is always the small things that get overlooked by myself and first project with MEAN stack doesn't help!
  • eafloresf
    eafloresf over 2 years
    I had the default port value to 3000 and that's why it wasn't working, I changed to that 5000 and it worked