Buzz
Buzz

Reputation: 325

Node: Cannot find module "mongoose" / Cannot install mongoose correctly

wenn i try to start a javascript-file with a test connection to mongodb then I get the Error message that the mongoose module cannot find. I have installed the mongoose with "npm install mongoose" in my node.js directory. But when I install mongoose then I get following messages, so I thin its not installed correctly:

> [email protected] install C:\Zimmermann\nodejs\node_modules\mongoose\node_module
s\mongodb\node_modules\mongodb-core\node_modules\kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)

C:\Zimmermann\nodejs\node_modules\mongoose\node_modules\mongodb\node_modules\mon
godb-core\node_modules\kerberos>if not defined npm_config_node_gyp (node "C:\Zim
mermann\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bi
n\node-gyp.js" rebuild )  else (rebuild)

> [email protected] install C:\Zimmermann\nodejs\node_modules\mongoose\node_modules\mo
ngodb\node_modules\mongodb-core\node_modules\bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)


C:\Zimmermann\nodejs\node_modules\mongoose\node_modules\mongodb\node_modules\mon
godb-core\node_modules\bson>if not defined npm_config_node_gyp (node "C:\Zimmerm
ann\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\no
de-gyp.js" rebuild )  else (rebuild)
[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])

What can I do that mongoose works correctly? Does anyone have an idea?

Best regards Benny

Upvotes: 0

Views: 6101

Answers (2)

satyam kumar
satyam kumar

Reputation: 1487

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 module.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 node.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 'node.js' directory, which means mongoose has been successfully installed.

Upvotes: 2

JoshWillik
JoshWillik

Reputation: 2645

This block

[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])

shows that mongoose has been installed correctly

You can use it like this

var mongoose = require( 'mongoose' )

If the install had failed, you would see a block that looks more like this:

npm ERR! tar.unpack untar error /home/josh/.npm/mongoose/4.0.1/package.tgz
npm ERR! Linux 3.19.3-3-ARCH
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "mongoose"
npm ERR! node v0.12.2
npm ERR! npm  v2.8.3
npm ERR! path /usr/lib/node_modules/mongoose
npm ERR! code EACCES
npm ERR! errno -13

npm ERR! Error: EACCES, mkdir '/usr/lib/node_modules/mongoose'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES, mkdir '/usr/lib/node_modules/mongoose']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/lib/node_modules/mongoose',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/lib/node_modules/mongoose',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53',
npm ERR!      'FSReqWrap.oncomplete (fs.js:95:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/josh/npm-debug.log

Takeaway

Output text does not mean the command failed. Look for actual error messages.

Upvotes: 0

Related Questions