Permalink
Browse files

Merge branch 'master' of git://github.com/chrisshoff/dynamic-node-ser…

…ver into shoffer/master
  • Loading branch information...
2 parents 43b8112 + bc9f44f commit 57a16a1710099988eca5914c02a0e2ccb8f5d6e8 @jimgeisler committed Feb 18, 2011
Showing with 39 additions and 6 deletions.
  1. +6 −0 README
  2. +5 −4 app.js
  3. +25 −0 js/database.js
  4. +3 −2 { → js}/features.js
  5. 0 { → js}/sample_features.js
View
6 README
@@ -2,6 +2,12 @@ The purpose of this project is to create a dynamic node.js server that can be ex
For now, it's only a quick skeleton with some sample features.
+Requires mongodb to be installed - can be installed via your package manager or from http://www.mongodb.org
+
+Also requires the mongodb native node.js driver - can be installed with npm using "npm install mongodb" or cloned from https://github.com/christkv/node-mongodb-native
+
+These dependencies may be added to the project at some point. Live with it for now.
+
Run with:
node app.js
View
9 app.js
@@ -1,9 +1,10 @@
var http = require('http'),
url = require('url'),
- Features = require('./features.js').Features,
- emitter = new(require('events').EventEmitter);
-
-features = new Features();
+ Features = require('./js/features.js').Features,
+ db = require('./js/database.js').db,
+ emitter = new(require('events').EventEmitter),
+
+features = new Features(db);
var app = http.createServer(function (req, res) {
features.execute(req, res, function(msg, success) {
View
@@ -0,0 +1,25 @@
+var sys = require('sys'),
+ Db = require('mongodb').Db,
+ Connection = require('mongodb').Connection,
+ Server = require('mongodb').Server,
+ BSON = require('mongodb').BSONNative;
+
+
+var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
+var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT'] : Connection.DEFAULT_PORT;
+
+var db = new Db('dynamic-node-server-mongo', new Server(host, port, {}), {native_parser:true});
+
+
+// Just a simple test to verify it's working.
+db.open(function(err, db) {
+ db.collection('features', function(err, collection) {
+ collection.insert({'a':1});
+ console.log('sample record added to db');
+ collection.remove(function(err, collection) {
+ console.log('sample record removed from db');
+ });
+ });
+});
+
+exports.db = db;
@@ -1,8 +1,9 @@
var url = require("url"),
sample_features = require("./sample_features.js");
-function Features() {
- this.feature_list = sample_features.get_sample_feature_list();
+function Features(db) {
+ this.db = db;
+ this.feature_list = sample_features.get_sample_feature_list(this.db);
this.parse_url = function(url_string, parse_qs) { return url.parse(url_string, parse_qs); }
this.execute = function(req, res, callback) {
File renamed without changes.

0 comments on commit 57a16a1

Please sign in to comment.