I am working a guide for an app using NodeJS, Express, MongoDB and React JS.I have a problem with the command: node server.js, it returns this:
I did try most of the proposed solutions found online:
- Deleting node_modules and package-lock.json && npm install
- Installing config module (deleted here)
- changed the location of the file and using different ways of writing the code:
./config/db.config.js
./db.config.js
Project structure:
db.config.js file content:
module.exports = { url: "mongodb://localhost:27017/the_project" };
app/models/index.js
const mongoose = require("mongoose");const dbConfig = require("../config/db.config.js");mongoose.Promise = global.Promise;const db = {};db.mongoose = mongoose;db.url = dbConfig.url;db.projects = require("./project.model.js")(mongoose);module.exports = db;
package.json:
{"name": "the_project","version": "1.0.0","description": "","main": "index.js","scripts": {"test": "echo \"Error: no test specified\" && exit 1" },"author": "Tibou","license": "ISC","dependencies": {"body-parser": "^1.20.0","cors": "^2.8.5","eslint": "^8.24.0","express": "^4.18.1","mongodb": "^4.10.0","mongoose": "^6.6.3","mongosh": "^0.0.1" }}
Mongosh showing the database: