Heroku Node.js App Works Locally but not when deployed
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
arahansen
Updated on June 23, 2022Comments
-
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 about 9 yearsis
bn
accidential or it is part of code -
arahansen about 9 yearsWoops. Good catch. That's not the issue though. Any other thoughts?
-
Tushar about 9 yearsThe
port
you are using for the server, is it free to use on deployment server -
arahansen about 9 yearsAgain, this function was behaving properly on localhost but acts up when deployed to heroku
-
arahansen about 9 years@Tushar I believe so. This app was working properly when deployed on Heroku prior to adding this functionality
-
Pankaj Parkar about 9 years@AndrewHansen are you using correct url while making
$http.get()
call? -
arahansen about 9 yearsI've updated my question with the client side code that is making the http request. Maybe there's an issue there?
-
-
arahansen about 9 yearsI've updated my question with the client side code that is making the http request. Maybe there's an issue there?
-
hunterloftis about 9 yearsIf you're getting a 503 on the server, you should really just check the server logs to see why.