I ran command: node server
in bash on Ubuntu and below is the error I got:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'mongojs'
Require stack:
- /home/nishil/Documents/contactListApp/server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/nishil/Documents/contactListApp/server.js:5:15)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/nishil/Documents/contactListApp/server.js' ]
}
How can I resolve this error?
CodePudding user response:
If you want to use mongojs or any other module, please make sure it's there in package.json and you have run yarn install or npm install in that directory containing the package.json. If the problem still persists, try deleting the node_modules folder in this directory and try running yarn install or npm install again.
CodePudding user response:
Please check in your package.json file if mongojs is installed or not. If it is then remove package-lock.json and remove node_modules folder and install node modules again by npm i.
If mongojs is not installed then you can do that using npm i mongojs
command
But i would suggest please change your package from mongojs to mongodb https://www.npmjs.com/package/mongodb
As mongojs is seems outdated its not updated since last 3 years it has 27 open issues since very long.
Let me know if this solutions works for you..