MongoDB: Cannot find module '/home/runner/boilerplate-mongomongoose/index.js'

Tell us what’s happening:

i created a
MongoDB cluster at https://cloud.mongodb.com

added a MONGO_URI with
my URL as Value

mongodb+srv://<my_cluster_name>:@cluster0.enwxxip.mongodb.net/?retryWrites=true&w=majority

yes i replaced
<my_cluster_name>

changed source at the app.js
https://replit.com/@sl5net/boilerplate-mongomongoose
to:

mongoose.connect(MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });

and also tried

let mongoose = require('mongoose');
mongoose.connect(MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });

was cloning the GitHub source to my repl and pressed run

and gut this error:

i got error:

Error: Cannot find module ‘/home/runner/boilerplate-project-urlshortener/index.js’

Your code so far

i tried to fix with:

means open

open .replit and run it

but same error.

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0

Challenge: MongoDB and Mongoose - Install and Set Up Mongoose

Link to the challenge:

Please post a link to your replit.

Did you use the Replit starter project referenced in the challenge instructions?

1 Like
https://replit.com/@sl5net/boilerplate-mongomongoose
its from 
https://github.com/freeCodeCamp/boilerplate-mongomongoose

You need to show hidden files by clicking on the 3 vertical dots and then open the .replit file and change index.js to server.js, because the app uses server.js as the entry point.

Once you fix that and click Run, you will get an error message that I believe you can easily fix.

thanks i changed.

now i get other error:

ReferenceError: MONGO_URI is not defined
at Object. (/home/runner/boilerplate-mongomongoose/myApp.js:4:18)

but i added it in the Secrets (without ’ or " )

I see:

mongoose.connect(MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });

I do not see where you defined a variable in your code named MONGO_URI. That is why you are getting the error. Look carefully at the example in the instructions on referencing the environment variable named MONGO_URI.

1 Like

its in the Secrets tab.
Screenshot_20230310_204501

In the previous curriculum section, do you not remember how to reference an environment variable? If not, I would review the previous app created, to see how you did it there.

The problem is not in the Secrets section. You are doing that correctly. The problem is how you are trying to reference that environment variable in the code.

1 Like

ahhh yes. ists not referenzed. seems i forgot it

No you did not. I just looked at your replit for the Express challenges and you did it correctly in your GET /json route.

process.env.
thanks and sorry :pray:

one of my problems is that i often mix to many program-styles and languages in my mind. and i usually use jetbrains - tools :wink: its nearly like a auto-correction-tool