Built URL Shortener Microservice in Cloud9, having trouble deploying to Heroku

I finally got my URL shortener working in Cloud9, but now I’m stuck trying to deploy to Heroku. For the previous API projects, I just chose Github as my deployment method and it was super easy.

Now I’ve tried the same approach and when my app launches the page just says “Application error: An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.”

Any suggestions for how to get through this? Does my Mongodb url need to be different from what it was in Cloud9?

Here’s all I’m getting from the logs:
2016-11-20T15:08:39.049274+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=my-urlshortener.herokuapp.com request_id=d2ba1850-c45c-4e00-aa5c-e05dd7e5da9d fwd="" dyno= connect= service= status=503 bytes=

Have you set your port correctly and in case you used environment variables, did you copy those?

Or maybe, can you show us your code?

Do you have these files? package.json app.json Procfiile

These files are important for heroku

I believe you don’t need those 2 (mine works without them), what do they do?

As far as I know Procfile is totally needed, but I could be wrong.

Procfile tells heroku how to start your program (lets heroku know its a back end is node)

app.json might not be necessary actually, just recamended maybe

Not sure what you’re using for mongo with cloud 9 but Heroku is going to need an external service like mLab to work properly. Maybe that’s the issue? The log files you’ve posted don’t seem to be of much help :confused:

Also as an alternative to Heroku, Hyperdev is a lot better, in my opinion (although pushing directly from github doesn’t work nearly as well).

Also pretty sure I’ve pushed from Github to Heroku without procfile or app.json and it works fine. You do need to put your server js file (ie the entry to your application) as the “start” file in package.json though. That’s a very common mistake too.

1 Like

Yeah, I don’t have app.json or procfile but have successfully pushed from Github to Heroku without them for the previous two API projects. I do have my server.js file as the start file.

I didn’t use mLab or anything. I used these instructions to set up Mongo on Cloud 9: https://community.c9.io/t/setting-up-mongodb/1717.

And this is the url for the db in my code.

Ah, there is now way Heroku can know about a local MongoDB. You will have to make a new database on mLab.

Gotcha – that makes sense. And I thought I was done with this challenge :slight_smile:

Maybe I need to put a Procfile because i don’t use my labtop with cloud9, I just use a linux computer at home, Im going to look into this more later on, because i thought it was mandatory, I’m glad to learn something new in this chat. Thank you. happy coding!!

I’m on Linux and never needed a procfile. Not actually sure what one does, but my apps are happy enough without them so I’ve never bothered to learn :slight_smile:

1 Like

Dang nabbit lol. I’m starting to feel like a fool lol.

So what does your dynos say?

mine says web node app.js (app.js being my starting file)