Package managers

xdamman edited this page Nov 26, 2012 · 1 revision
Clone this wiki locally

npm

Run:

npm install mongodb

native / manual

create a subfolder “deps”
enter to it, clone it with git

Run:

cd deps

Run:

git clone http://github.com/christkv/node-mongodb-native.git

Use it like:

require.paths.unshift(__dirname); 

var http = require('http'); // http server if you like

var mongo = require('deps/node-mongodb-native/lib/mongodb'); 

//probably you might need the ObjectID later:
//var ObjectID= require('deps/node-mongodb-native/lib/mongodb/bson/bson').ObjectID; 

db = new mongo.Db(
         'database_name', //dbname
         new mongo.Server(  'localhost', // host
                                           27017 // port default 27017
                                          , {}), {});
db.addListener("error", function(error) {
   sys.puts("Error connecting to mongo -- perhaps it isn't running?"); });

db.open(function(p_db)
{

  yourapp.init(db,
  function (){

   http.createServer(function (req,res){
    ...
   }).listen(8080);

 });

});