I'm trying to make a microblog web app width nodejs, express and mongodb. But I came up with a problem that my app cannot access to the database.
My package.json goes like these:
{
"name": "microblog"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"express": "2.5.8"
, "ejs": "0.0.1"
, "connect-mongo" : "0.1.7"
, "mongodb" : "0.9.9"
}
}
Configuration goes like these:
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({
secret: settings.cookieSecret,
store: new MongoStore({
db: settings.db
})
}));
app.use(express.router(routes));
app.use(express.static(__dirname + '/public'));
});
I create a mongodb with db.js in directory models:
module.exports = {
cookieSecret: 'microblog',
db: 'microblog',
host: 'localhost'
}
With all above I just tried to debug my app to see if the app can successfully connect to the database. Then comes this problem:
/home/edward/github/nodejs/microblog/node_modules/connect-mongo/lib/connect-mongo.js:114
throw new Error('Error connecting to database');
^
Error: Error connecting to database
at /home/edward/github/nodejs/microblog/node_modules/connect-mongo/lib/connect-mongo.js:114:13
at /home/edward/github/nodejs/microblog/node_modules/mongodb/lib/mongodb/db.js:240:16
at null.<anonymous> (/home/edward/github/nodejs/microblog/node_modules/mongodb/lib/mongodb/connection/server.js:390:7)
at EventEmitter.emit (events.js:95:17)
at null.<anonymous> (/home/edward/github/nodejs/microblog/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:96:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (/home/edward/github/nodejs/microblog/node_modules/mongodb/lib/mongodb/connection/connection.js:388:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:415:13)
It sucks me so much time and I just can't find a way to get out of this. Finally I have to post it here. Any guidance are appreciated. :)
Have you installed and configured the mongoDB server as detailed here:
http://docs.mongodb.org/manual/installation/
Sounds like there is not a MongoDb server running on localhost.