Can anyone help with my express app, having trouble hosting on heroku

hi, I am having trouble with app not hosting on heroku, I have built it using express, knex and postgresql.

the GitHub repo is: https://github.com/jamesgill11/Quiz_server.git

when I run heroku logs --tail I get these error messages:

2021-02-22T19:13:25.130322+00:00 heroku[router]: at=info method=GET path="/" host=my-new-quiz.herokuapp.com request_id=4b883007-74e1-416b-a119-9634a329fd6d fwd=“188.223.116.76” dyno=web.1 connect=0ms service=249ms status=404 bytes=281 protocol=https
2021-02-22T19:13:25.232084+00:00 heroku[router]: at=info method=GET path="/favicon.ico" request_id=df6434eb-60b4-4fba-8adc-7aebd428151b fwd=“188.223.116.76” dyno=web.1 connect=0ms service=8ms status=404 bytes=281 protocol=https
2021-02-22T19:13:36.855067+00:00 heroku[router]: at=info method=GET path="/" request_id=592682a0-16ba-43db-a842-707c84394ff1 fwd=“188.223.116.76” dyno=web.1 connect=1ms service=5ms status=404 bytes=281 protocol=https
2021-02-22T19:13:37.108557+00:00 heroku[router]: at=info method=GET path="/api/questions"request_id=2095e990-89bd-4188-997e-58d034de634a fwd=“188.223.116.76” dyno=web.1 connect=1ms service=77ms status=500 bytes=289 protocol=https
2021-02-22T19:13:37.202830+00:00 heroku[router]: at=info method=GET path="/favicon.ico"request_id=e69860f4-fca9-44e1-9bb2-b5e370804aca fwd=“188.223.116.76” dyno=web.1 connect=0ms service=2ms status=404 bytes=281 protocol=https
2021-02-22T19:13:37.224465+00:00 heroku[router]: at=info method=GET path="/api/“request_id=6ca1c9e4-e263-4080-9e69-792202c6f5cf fwd=“188.223.116.76” dyno=web.1 connect=1ms service=7ms status=405 bytes=283 protocol=https
2021-02-22T19:13:40.862501+00:00 heroku[router]: at=info method=GET path=”/api/questions" request_id=76dca2ac-40f7-46f5-8b6b-fc7b3d9eb6a8 fwd=“188.223.116.76” dyno=web.1 connect=1ms service=29ms status=500 bytes=289 protocol=https
2021-02-22T19:13:40.963861+00:00 heroku[router]: at=info method=GET path="/favicon.ico" request_id=fbdebd0c-89c0-410f-be12-ca9b1c35d18d fwd=“188.223.116.76” dyno=web.1 connect=1ms service=5ms status=404 bytes=281 protocol=https

but I don’t have a /favicon.ico in my code?? and all my code seems to work locally!

thanks in advance for any help given. literally pulling my hair out :slight_smile:

GET /api/questions is returning 500.
First thing I’d check is if database url is added to config values.

I sometimes forget to add the environment variables in heroku. You can input them in the Settings tab on the heroku dashboard.

thanks for replying, I have checked this, the database url is correct in config vars

thanks for replying, environment variables as in production??

Yeah everything in your .env file in your local app you need to add in the heroku dashboard as the .env file isn’t (shouldn’t be) pushed to the github repo which your heroku app is using,

It’s an obvious thing but it’s tripped me up a few times as I’ve just forgot to input them in heroku.

Not sure if that’s the problem just throwing it out there.

ahh I see what you mean. yeah I tried it, didn’t work. thanks for trying though

I’m not familiar with knex, but isn’t your knexfile.js with config also required in production? I see production key there, but in connection.js file you ignore it in production.

that checks whether I am in production mode and if so it will connect to my production database otherwise it will connect to my (.gitignore’d) knex file

I understand that, but what confused me is that config structure in both cases is different.

yes sorry, it was just how I was taught to do it. I have another app, where the configs are built in the same way and it hosts fine. that’s why I can’t understand what I am doing wrong here because if anything this is a much smaller app.

so when I run the code in the environment development, it works fine but the moment I change it to production, that’s when I get “internal server error”.

Add console.log in your 500 error handler (or send it back in api response) so you can see what kind of error is causing your server to crash.

so did this, I am getting this error -

Error: Unable to acquire a connection
at Client_PG.acquireConnection (/Users/jamesgill/Desktop/todoList/Quiz/Quiz-server/node_modules/knex/lib/client.js:339:13)
at Runner.ensureConnection (/Users/jamesgill/Desktop/todoList/Quiz/Quiz-server/node_modules/knex/lib/runner.js:264:8)

it looks like its not connecting to the PG database on heroku. I have tried changing the connectionString in the knexfile.js to the actually Postgres_url string but its still having none of it and will not connect.

But your code is not using knexfile in prod :thinking:

good point :man_facepalming: , I thought it might be with me running pg @ 12 as I was getting a warning saying pg was 12 and server was 13. so updated, that hasn’t worked either :pensive:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.