Technologies:
Tolerim
11 hours ago
My Heroku hosted web app displays no traffic, unlike MongoDB.
heroku logs --tail
command output is as follows:
2023-05-03T15:42:24.967086+00:00 heroku[router]: at=info method=GET path="/dishes/new" host=foodapp-tempname.herokuapp.com request_id=a06152cc-e859-488c-8190-4aa52ad5876f fwd="88.94.13.75" dyno=web.1 connect=0ms service=26ms status=304 bytes=152 protocol=https
2023-05-03T15:42:25.363928+00:00 heroku[router]: at=info method=GET path="/goods" host=foodapp-tempname.herokuapp.com request_id=72c1c5aa-e750-4fa1-a27b-d714207ff786 fwd="88.94.13.75" dyno=web.1 connect=0ms service=26ms status=304 bytes=151 protocol=https
2023-05-03T15:42:25.951913+00:00 heroku[router]: at=info method=GET path="/dishes" host=foodapp-tempname.herokuapp.com request_id=e54a38e5-d45c-4ddf-b647-a9cf217c8e4e fwd="88.94.13.75" dyno=web.1 connect=0ms service=26ms status=304 bytes=151 protocol=https
I confirmed that the proper Environment Variables exist on Heroku: mongodb+srv://<myUsername>:<myPassword>@foodappcluster.uomno4t.mongodb.net/?retryWrites=true&w=majority
enter image description here Before loading the .env
file, I have an if statement verifying if the app is in production:from server.js My .gitignore
file contains.env
andnode_modules
.
Answers(1)
Tolerim
11 hours ago
Verified Answer
It sounds like there might be an issue connecting to MongoDB on Heroku, but since there are no error messages it's hard to be sure. Here are some suggestions:
- Make sure that you have allowed access to your MongoDB cluster from all IP addresses (0.0.0.0/0). You can check this in the MongoDB Atlas dashboard under "Network Access".
- Double-check that your connection string in the Heroku environment variables is correct and doesn't contain any typos or errors.
- Try logging more information in your Node.js app by using console.log statements or a debugging library like debug or winston. This might help you identify where the issue is happening in your code.
- Check the Heroku logs for any errors or warning messages. You can use the Heroku command heroku logs --tail to stream the logs in real-time.
- If you're still having issues, you can try using a MongoDB client like Robo 3T to connect to your cluster and see if you can access the data.