I am getting the following error while trying to run server using Node.ja with Mongodb.
Error:
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
C:\xampp\htdocs\odiya_chat\server.js:15
db = mongo.connect("127.0.0.1:27017/"+db, collections);
^
TypeError: Object function (connString, cols) {
var dbname = getDbName(connString);
var onserver = thunky(function(cb) {
getTopology(connString, function(err, topology) {
if (err) return cb(err);
cb(null, topology);
});
});
if (!dbname) {
dbname = connString._dbname;
onserver = thunky(function(cb) {
toMongodbCore(connString, function(err, server) {
if (err) cb(new Error('You must pass a connection string or a mongojs in
stance.'));
cb(null, server);
});
});
}
var that = new Database({name: dbname, cols: cols}, onserver);
if (typeof Proxy !== 'undefined') {
var p = Proxy.create({
get: function(obj, prop) {
if (that[prop]) return that[prop];
that[prop] = that.collection(prop);
return that[prop];
}
});
return p;
};
return that;
} has no method 'connect'
at Object.<anonymous> (C:\xampp\htdocs\odiya_chat\server.js:15:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3
Error-2
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
My server side code is given below.
Server.js
var port=8888;
var express=require('express');
var http=require('http');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var MongoDBStore = require('connect-mongodb-session')(session);
var mongo = require('mongojs');
var app=express();
var server=http.createServer(app);
db = 'doctor',
collections = ['oditek'],
db = mongo.connect("127.0.0.1:27017/"+db, collections);
app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded
app.use(bodyParser.json()) // parse application/json
app.use(methodOverride());
app.use(cookieParser());
//app.use(expressSession({secret:'somesecrettokenhere'})); // simulate DELETE and PUT
app.get('/',function(req,res){
res.sendfile('view/index.html');
})
app.get('/login',function(req,res){
res.sendfile('view/login.html');
});
app.get('/chatroom',function(req,res){
if(req.session){
res.sendfile('view/chatroom.html');
}
});
server.listen(port);
console.log('server is running on the port'+port);
Here My requirement is If user is already logged in client side he will get the chatroom.html page and if not in client side it will ask you for login.I am implementing here connect-mongodb-session
for store the session.I have read some posts regarding this and tried the answer but still error was there.Please help me to resolve this error.