Heroku Node.js App Works Locally but not when deployed

10,346

Solution 1

Well, I actually figured it out. Turns out I hadn't listed all my dependencies in my package.json.

Lesson here: when installing node packages always use --save

Or you're gonna have a bad time.

Solution 2

Try to recompile (ng build -prod) Angular side and deploy it again. Also watch MEAN Stack Front To Back [Part 10] - App Deployment to Heroku

Solution 3

Nothing in that block of code is inherently broken.

Just check the logs to see what's giving you errors:

heroku logs --tail
Share:
10,346
arahansen
Author by

arahansen

Updated on June 23, 2022

Comments

  • arahansen
    arahansen almost 2 years

    I have a MEAN Stack Heroku app that was running just fine. But then I added a new function:

    app.get('/userCreated/:id', function(req, res) {
    
    if (req.cookies.userCreated == req.params.id) { 
        res.send(true);
    }
    else {
        res.send(false);
    }
    
    });
    

    And now I get a 503 (Service Unavailable) error upon loading the app. Anyone have an idea why this might be?

    I'm using Angular and $http.get() to access this Express.js function...

    Edit: here is my client side Angular code that is making a call to the server:

    var deferred = $q.defer();
    function thisUserCreated(id) {
    $http.get('/userCreated/' + id).success(function(data) {
    deferred.resolve(data);
    // returns boolean indicating whether the current user has the proper cookie
    // saying this user created the given group
    });
    return deferred.promise;
    };
    
    • Tushar
      Tushar about 9 years
      is bn accidential or it is part of code
    • arahansen
      arahansen about 9 years
      Woops. Good catch. That's not the issue though. Any other thoughts?
    • Tushar
      Tushar about 9 years
      The port you are using for the server, is it free to use on deployment server
    • arahansen
      arahansen about 9 years
      Again, this function was behaving properly on localhost but acts up when deployed to heroku
    • arahansen
      arahansen about 9 years
      @Tushar I believe so. This app was working properly when deployed on Heroku prior to adding this functionality
    • Pankaj Parkar
      Pankaj Parkar about 9 years
      @AndrewHansen are you using correct url while making $http.get() call?
    • arahansen
      arahansen about 9 years
      I've updated my question with the client side code that is making the http request. Maybe there's an issue there?
  • arahansen
    arahansen about 9 years
    I've updated my question with the client side code that is making the http request. Maybe there's an issue there?
  • hunterloftis
    hunterloftis about 9 years
    If you're getting a 503 on the server, you should really just check the server logs to see why.