First of, I already searched forum, but the problem cannot be resolved by following those suggestions already given. Replit no longer accepts .env files and FCC guide is now outdated. Hence, asking over again.
Tell us what’s happening:
I managed to find the way to connect to my MongoDB database circumventing need for .env file. For this I have copied full driver code example generated on MongoDB’s ‘Connect to Cluster’ section. So when I run a code on Replit I am able to connect to Mongo database. But FCC test fails throwing this error: ‘“mongoose” should be connected to a database’.
Was anyone able to pass FCC test recently. If so how you did it please?
The guide is a bit outdated, but all the information is relevant. Replit just moved to using their SECRETS tab for environment variables. Otherwise, the mechanics are the same:
Add an environment variable and give it a value
Access the environment variable value with process.env.<variable_name>
I belive the reason the tests are failing for you is because you are not connecting Mongoose:
Thank you for confirming that FCC tests are not outdated and still working. I much needed that assurance.
I was able to pass all 3 tests after starting on new Replit repository and following FCC guides but only changing the bit concerning .env files.
To whomever needs guidance, this is how I did it:
Add mongodb@~3.6.0 and mongoose@~5.4.0 to the project’s package.json.
Then, require mongoose as mongoose in myApp.js.
Add MONGO_URI key in Replit’s secrets and paste the URI value copied from MongoDB Atlas database URI. No need to add single or double quotes, just copy+paste. You only need to change password here.
Replit’s secrets are hidden and you can make use of by inserting process.env['MONGO_URI'] wherever you need that value (URI in our case).