0

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.

satya
  • 3,508
  • 11
  • 50
  • 130

1 Answers1

1

Since you're using the mongojs module, you're going to have to connect to the database using the following method

db = mongo("127.0.0.1:27017/"+db, collections);
Bidhan
  • 10,607
  • 3
  • 39
  • 50
  • @ Bidhan : Thanks its started work now but still the some errors are there and i have post those error in my question as Error-2. – satya Jun 15 '15 at 06:22
  • Those aren't errors. Only warnings. It means that instead of using bson version which is fast, you are running JS version, which is slower. This happens due to problems with different versions of your modules. Your app should still run fine though. Is your app running? – Bidhan Jun 15 '15 at 06:33
  • Yes Bidhan it is running fine but those messages were there thats why i asked..Is there any solution to remove these..? – satya Jun 15 '15 at 06:35
  • There have been many discussions on Stack Overflow regarding those warning messages. For example: http://stackoverflow.com/questions/28651028/cannot-find-module-build-release-bson-code-module-not-found-js-bson . Some people are able to solve it, some aren't. It usually happens due to mismatch between different versions of libraries that you are using. Maybe switching to an older version of mongojs might help but I'm not 100% sure. – Bidhan Jun 15 '15 at 06:42