11 hours ago

My Heroku hosted web app displays no traffic, unlike MongoDB.

My Node.js app functions perfectly on localhost, connecting and communicating with MongoDB without issues and rendering all data accordingly on the client-side. However, when the app is hosted on Heroku, while the links work as intended, the data from MongoDB is not displaying. To investigate, I visited the MongoDB website and checked the analytics section for traffic information, which displayed graphs indicating activity. Despite this, the information is not visible on Heroku as it is on localhost. I have not encountered any error messages, only missing data. The 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" request_id=a06152cc-e859-488c-8190-4aa52ad5876f fwd="" 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" request_id=72c1c5aa-e750-4fa1-a27b-d714207ff786 fwd="" 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" request_id=e54a38e5-d45c-4ddf-b647-a9cf217c8e4e fwd="" dyno=web.1 connect=0ms service=26ms status=304 bytes=151 protocol=https
  • I confirmed that the proper Environment Variables exist on Heroku:


    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 and node_modules.

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 ( 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.