Node.js error Error: Cannot find module 'mongoose'
Solution 1
try installing mongoose using this command:
npm install mongoose
do not use the -g switch.
BTW: I ran command prompt in admin mode. Reference
Solution 2
You can do either of two things to make it run :-
1) Install mongoose globally with below steps :-
a)npm install mongoose -g
b) Go to your app directory, where bot.js is located and then run
npm link mongoose
Explanation :- When you install a package globally via npm, it is downloaded to global node_module folder. For me(Mac user), it's under /usr/local/lib/node_modules/mongoose. We link this to that directory from where you are trying to run module.js.
2) Another approach is to install mongoose locally, not globally via
npm install mongoose
After following either of these, you will be seeing node_modules --> mongoose folder under the 'bot.js' directory, which means mongoose has been successfully installed.
Now, run node bot.js , it will work .
Solution 3
Install with the --save
option:
npm install mongoose --save
This adds mongoose it to package.json
which Heroku uses to build your app.
Solution 4
You have to call in the command line
npm install mongoose
remember to call this command from the root path of your project
Solution 5
npm install mongoose
it will work and if everything is alright then you will get following in your terminal
[email protected] node_modules/mongoose
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected])
Admin
Updated on September 10, 2021Comments
-
Admin over 2 years
C:\Users\Nick\Desktop\turntablefm\Bots\Super Bot>node bot.js node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: Cannot find module 'mongoose' at Function._resolveFilename (module.js:334:11) at Function._load (module.js:279:25) at Module.require (module.js:357:17) at require (module.js:368:17) at Object.<anonymous> (C:\Users\Nick\Desktop\turntablefm\Bots\Super Bot\db.j s:1:78) at Module._compile (module.js:432:26) at Object..js (module.js:450:10) at Module.load (module.js:351:31) at Function._load (module.js:310:12) at Module.require (module.js:357:17)
I already installed it using npm install and I tried reinstalling but that didn't work any ideas?