Skip to content

Commit

Permalink
update node.js back-end example to refect mongodb native drive 2.0.x …
Browse files Browse the repository at this point in the history
…changes
  • Loading branch information
azat-co committed Jun 24, 2015
1 parent 6e120f2 commit be00e6c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
6 changes: 3 additions & 3 deletions 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"
Expand Down
14 changes: 7 additions & 7 deletions node/web.js
Expand Up @@ -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") {
Expand All @@ -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: ")
Expand All @@ -57,7 +57,7 @@ mongo.Db.connect(host, function(error, client) {
'Content-Length':body.length
});
response.end(body);
})
})
})

};
Expand Down
26 changes: 15 additions & 11 deletions readme.md
Expand Up @@ -6,59 +6,63 @@ 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)

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
Expand Down

0 comments on commit be00e6c

Please sign in to comment.