Hi,
I will apologise for this long winded post but after quite a bit of Googling I think needs must.
I am making my through a
node.js book and Iam working through the chapter that introduces the MongoDB. Firstly, I have installed MongoDB and seems to be running as a service on my Windows 7 PC. Also I have installed MongoVUE and this seems to installed ok.
The purpose of this exercise (see attached zip) is to just connect to the MongoDB.
So in the node.js command prompt (Run as administrator) I use the following commands:
- express connect_to_mongo
- cd connect_to_mogo
- npm install
So in my root folder I now have connect_to_mongo folder with the installation going ok
Then the package.json is edited to:
{
"name":"application-name",
"version":"0.0.1",
"private":true,
"dependencies":{
"express":"2.5.1",
"jade":">= 0.0.1",
"mongoose":">= 2.3.1"
}
}
Then the app.js is edited to include:
var express = require('express'),
routes = require('./routes'),
mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/todo_development', function(err) {
if (!err) {
console.log('connected to MongoDB');
} else {
throw err;
}
});
With all of this saved I then try to fire this up with: node app.js and get the following error:
C:\Users\Dave Johnson\Desktop\shapeshed-nodejsbook.io.examples-e2ece11\hour08\ex
ample04\connect_to_mongo>node app.js
module.js:340
throw err;
^
Error: Cannot find module 'mongoose'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (C:\Users\Dave Johnson\Desktop\
shapeshed-nodejsbook.io.examples-e2ece11\hour08\example04\connect_to_mongo\app.js:8:16)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
Unless I am missing something the book only seems to ask for mongoose to be listed as dependancy and then reference it in the app.js.
But I even tried adding it with express mongoose and then installing it in 1. root folder, 2. the connect_to_mongo folder & 3. the node_modules folder and still get the same error.
I hope I am making sense and if so please help me if you can.
Thanks, Dave.