So I'm attempting to launch my node app, but there's a few errors arising from my MongoDB installation.
Here are the specs for my dev environment:
node => 0.10.33 (installed from nodejs.org)
npm => 1.4.28 (installed from nodejs.org)
git => 2.1.3 (homebrewed)
mongodb => 2.6.5 (homebrewed)
If it makes a difference, I am also using the Mean Stack Skeleton as part of a tutorial.
In a nutshell, when I try to run my node app using $ node app.js
, I get the following feedback:
USER$ npm install mongoose
> kerberos@0.0.4 install /Users/USER/APP/node_modules/mongoose/node_modules/mongodb/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/kerberos/lib/kerberos.o
CXX(target) Release/obj.target/kerberos/lib/worker.o
CC(target) Release/obj.target/kerberos/lib/kerberosgss.o
CC(target) Release/obj.target/kerberos/lib/base64.o
CXX(target) Release/obj.target/kerberos/lib/kerberos_context.o
SOLINK_MODULE(target) Release/kerberos.node
SOLINK_MODULE(target) Release/kerberos.node: Finished
> bson@0.2.15 install /Users/USER/APP/node_modules/mongoose/node_modules/mongodb/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/bson/ext/bson.o
SOLINK_MODULE(target) Release/bson.node
SOLINK_MODULE(target) Release/bson.node: Finished
mongoose@3.8.18 node_modules/mongoose
├── regexp-clone@0.0.1
├── muri@0.3.1
├── sliced@0.0.5
├── hooks@0.2.1
├── mpath@0.1.1
├── mpromise@0.4.3
├── ms@0.1.0
├── mquery@0.8.0 (debug@0.7.4)
└── mongodb@1.4.12 (readable-stream@1.0.33, kerberos@0.0.4, bson@0.2.15)
I checked the builderror.log
files for both the kerberos
and bson
modules. However, both are empty.
Some research I have found suggests that the issue might be because my node-gyp
installation does not have a corresponding binding.gyp
file.
Also tried running $ node-gyp configure
inside my Node.js project folder. And this is the error I received:
gyp: binding.gyp not found (cwd: /Users/USER/APP) while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/node-gyp/lib/configure.js:343:16)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:810:12)
gyp ERR! System Darwin 12.5.0
gyp ERR! command "node" "/usr/local/bin/node-gyp" "configure"
gyp ERR! cwd /Users/USER/APP
gyp ERR! node -v v0.10.33
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok
Any ideas why I am having these issues?
EDIT: After setting the port in my app.js
file to set the port to the same one that the Express server is listening on (duh), I get more feedback indicating that I was using Mongoose 3.9.4, which is the latest unstable release of mongoose
. So I set the module to 3.8.18 in my package.json
and attempted to reinstall the module. I received the same errors. However, the unstable release feedback is gone now.
After I cd
'd into the kerberos
and bson
directories, I used the command $ node-gyp rebuild
and the node modules compiled correctly.
My app.js
file, I called the following lines:
var app = express();
...
var Mongoose = require('mongoose');
var db = Mongoose.createConnection('localhost','database');
// all environments
app.set('port', process.env.PORT || 3000);
This port number must be unique from the port of your database instance.
In a separate terminal window, run $ mongod
to spool up your MongoDB. Once it's called, in yet another terminal window, you call $ mongo database
. This creates the database instance called database
for your Node.js app to connect to. In your original terminal window, call $ node app.js
and it will run without any error feedback.
The errors I was getting were not the result of an incorrect build of Mongoose, MongoDB or any of their dependencies. The errors were a result of a misconception about MongoDB. MongoDB must be running as a process separate to your Node.js app in order for the app to make a database connection.