diff --git a/node/package.json b/node/package.json index e589b58..3663c10 100644 --- a/node/package.json +++ b/node/package.json @@ -1,9 +1,9 @@ { "name": "node-example", - "version": "0.0.1", + "version": "1.0.1", "dependencies": { - "mongodb":"", - "url":"" + "mongodb": "2.0.35", + "url": "" }, "engines": { "node": ">=0.6.x" diff --git a/node/web.js b/node/web.js index 8fbb9a5..6b33687 100644 --- a/node/web.js +++ b/node/web.js @@ -11,21 +11,21 @@ var mongo = require('mongodb'); var host = process.env.MONGOHQ_URL || "mongodb://localhost:27017/board"; //MONGOHQ_URL=mongodb://user:pass@server.mongohq.com/db_name - -mongo.Db.connect(host, function(error, client) { +var MongoClient = mongo.MongoClient +MongoClient.connect(host, function(error, db) { if (error) throw error; - var collection = new mongo.Collection(client, 'messages'); + var collection = db.collection('messages'); var app = http.createServer( function (request, response) { var origin = (request.headers.origin || "*"); if (request.method=="OPTIONS") { response.writeHead("204", "No Content", { "Access-Control-Allow-Origin": origin, - "Access-Control-Allow-Methods": + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", "Access-Control-Allow-Headers": "content-type, accept", "Access-Control-Max-Age": 10, // Seconds. "Content-Length": 0 - }); + }); response.end(); }; if (request.method==="GET"&&request.url==="/messages/list.json") { @@ -45,7 +45,7 @@ mongo.Db.connect(host, function(error, client) { request.on('data', function(data) { console.log("RECEIVED DATA:") console.log(data.toString('utf-8')); - collection.insert(JSON.parse(data.toString('utf-8')), + collection.insert(JSON.parse(data.toString('utf-8')), {safe:true}, function(error, obj) { if (error) throw error; console.log("OBJECT IS SAVED: ") @@ -57,7 +57,7 @@ mongo.Db.connect(host, function(error, client) { 'Content-Length':body.length }); response.end(body); - }) + }) }) }; diff --git a/readme.md b/readme.md index 15983b3..788d9b1 100644 --- a/readme.md +++ b/readme.md @@ -6,20 +6,20 @@ Rapid Prototyping with JS is a JavaScript and Node.js book that will teach you h ## Part II — Building Front-End Application * [bootstrap](https://github.com/azat-co/rpjs/tree/master/bootstrap) - + [Twitter Bootstrap] scaffolding example * [jQuery](https://github.com/azat-co/rpjs/tree/master/jquery) - + [jQuery], Twitter API and JSONP example * [parse](https://github.com/azat-co/rpjs/tree/master/parse) - + Simple example of [Parse.com] JavaScript SDK * [rest](https://github.com/azat-co/rpjs/tree/master/rest) - + Chat front-end: [jQuery] and [Parse.com] REST API; ready for deployment. * [backbone](https://github.com/azat-co/rpjs/tree/master/backbone) @@ -27,38 +27,42 @@ Rapid Prototyping with JS is a JavaScript and Node.js book that will teach you h Diving Deeper into Backbone.js * [sdk](https://github.com/azat-co/rpjs/tree/master/sdk) - + [BackboneJS] and [Parse.com] SDK Chat ## Part III — Building Back-End Application * [hello](https://github.com/azat-co/rpjs/tree/master/hello) - + [NodeJS] "Hello World" app, ready for deployment - + * [test](https://github.com/azat-co/rpjs/tree/master/test) Chat back-end: TDD with run-time storage * [db](https://github.com/azat-co/rpjs/tree/master/db) - + Simple app to test local database connection with MongoDB Native Driver * [mongo](https://github.com/azat-co/rpjs/tree/master/mongo) - + Chat back-end: [MongoDB] storage, ready for deployment ## Part IV — Putting it All Together * [board](https://github.com/azat-co/rpjs/tree/master/board) - Chat front-end with our back end + Chat front-end without back end * [node](https://github.com/azat-co/rpjs/tree/master/node) - + Chat back-end with CORS +### Part V — Beyond Core Modules + +* [board-react](https://github.com/azat-co/rpjs/tree/master/board-react) + Chat with React.js view layer [BackboneJS]: http://backbonejs.org [UnderscoreJS]: http://underscorejs.org