MongoDB and Mongoose - Install and Set Up Mongoose

Please help! I’m using Replit and I’m trying to get past the first challenge in the MongoDB and Mongoose course but I keep getting the following error after following the instructions:

Error: Cannot find module ‘/home/runner/boilerplate-mongomongoose/index.js’
Require stack:

  • /nix/store/29fdcv1yhlll61ml8a31qdkrbprxd7gs-prybar-nodejs-0.0.0-67f7a00/prybar_assets/nodejs/module-context-hook.js
  • /tmp/prybar-nodejs-801678351.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)

I’m not sure but I think it has to do with an index.js file which is not present in the repository imported from GitHub. My myApp.js code is:

require(‘dotenv’).config();

const mongoose = require(“mongoose”);
mongoose.connect(“mongodb+srv://Olumuyiwa:@cluster0.zpkhjak.mongodb.net/fcc-mongodb-and-mongoose?retryWrites=true&w=majority”, { useNewUrlParser: true, useUnifiedTopology: true });

let Person;

const createAndSavePerson = (done) => {
done(null /, data/);
};

const createManyPeople = (arrayOfPeople, done) => {
done(null /, data/);
};

const findPeopleByName = (personName, done) => {
done(null /, data/);
};

const findOneByFood = (food, done) => {
done(null /, data/);
};

const findPersonById = (personId, done) => {
done(null /, data/);
};

const findEditThenSave = (personId, done) => {
const foodToAdd = “hamburger”;

done(null /, data/);
};

const findAndUpdate = (personName, done) => {
const ageToSet = 20;

done(null /, data/);
};

const removeById = (personId, done) => {
done(null /, data/);
};

const removeManyPeople = (done) => {
const nameToRemove = “Mary”;

done(null /, data/);
};

const queryChain = (done) => {
const foodToSearch = “burrito”;

done(null /, data/);
};

/** Well Done !!
/* You completed these challenges, let’s go celebrate !
*/

//----- DO NOT EDIT BELOW THIS LINE ----------------------------------

exports.PersonModel = Person;
exports.createAndSavePerson = createAndSavePerson;
exports.findPeopleByName = findPeopleByName;
exports.findOneByFood = findOneByFood;
exports.findPersonById = findPersonById;
exports.findEditThenSave = findEditThenSave;
exports.findAndUpdate = findAndUpdate;
exports.createManyPeople = createManyPeople;
exports.removeById = removeById;
exports.removeManyPeople = removeManyPeople;
exports.queryChain = queryChain;


My package.json is:
{
“name”: “fcc-mongo-mongoose-challenges”,
“version”: “0.0.1”,
“description”: “A boilerplate project”,
“main”: “server.js”,
“scripts”: {
“start”: “node server.js”
},
“dependencies”: {
“body-parser”: “^1.15.2”,
“dotenv”: “^8.2.0”,
“express”: “^4.12.4”,
“mongoose”: “^5.11.15”
},
“repository”: {
“type”: “git”,
“url”: “GitHub - freeCodeCamp/boilerplate-mongomongoose: A boilerplate for the freeCodeCamp curriculum.
},
“keywords”: [
“node”,
“mongoose”,
“express”
],
“license”: “MIT”
}

Using the Secrets tab in Replit, my MONGO_URI is precisely the URI I passed in mongoose.connect

Your project link(s)

solution: boilerplate-mongomongoose - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0

Challenge: MongoDB and Mongoose - Install and Set Up Mongoose

No I wasn’t able to resolve it

You deleted the Replit. Can you replicate the issue in a new one?

I have done that now, the link to the Repl now works

const mongoose = require(“mongoose”);

You are using the wrong type of quotes for the require string. It has to be normal double "" or single '' quotes. When I fix that and run the test it passes (with a fork of your project).

Wowwwww!!! It works now! Thank you so much :hugs:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.