How I solved the "Invalid connection string" error on Heroku

Introduction

Today on my blog, I will talk about how I solved a bug that plagued me for 3 days without end. Okay, here we go!!

I started learning Nodejs about 4 months ago. Having hosted 2 apps on heroku, I pretty had a good feeling about how it works and all that. But like what we all know, sometimes things happen that we don't plan for.

I joined the Zuri Internship program. There we were given tasks to build projects. One of the projects given was to build a CRUD app that handles clients' requests which cut across, signing up, updating, deleting users, and getting a list of users or a specific user.

Challenges I faced

After pushing to GitHub and hosting on Heroku, I tested for possible app errors. I discovered an 'invalid connection string" error about a day later. I tested the app locally, it was okay. Solutions on StackOverflow didn't cut it for me.

I copied and pasted the connection string from MongoDB atlas several times but still the same issue. I imported the "dotenv" npm package in my file locally but still the same issue.

How did I solve it?

I generated a random password on the MongoDB cluster, copied and pasted it in the connection string, then changed it back to the previous password. That was what solved it for me.

You might have come across similar errors, please share in the comment section. I would also love to hear and learn from you.

I would love to meet you. Please follow me on Twitter and LinkedIn