Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Error: Cannot find module '../config./db.config.js'

$
0
0

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:enter image description here

I did try most of the proposed solutions found online:

  1. Deleting node_modules and package-lock.json && npm install
  2. Installing config module (deleted here)
  3. changed the location of the file and using different ways of writing the code: ./config/db.config.js./db.config.js

Project structure:

structure of the project

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:

enter image description here


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>