Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/chrisshoff/dynamic-node-ser…
Browse files Browse the repository at this point in the history
…ver into shoffer/master
  • Loading branch information
jimgeisler committed Feb 18, 2011
2 parents 43b8112 + bc9f44f commit 57a16a1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README
Expand Up @@ -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. 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: Run with:


node app.js node app.js
9 changes: 5 additions & 4 deletions app.js
@@ -1,9 +1,10 @@
var http = require('http'), var http = require('http'),
url = require('url'), url = require('url'),
Features = require('./features.js').Features, Features = require('./js/features.js').Features,
emitter = new(require('events').EventEmitter); db = require('./js/database.js').db,

emitter = new(require('events').EventEmitter),
features = new Features();
features = new Features(db);


var app = http.createServer(function (req, res) { var app = http.createServer(function (req, res) {
features.execute(req, res, function(msg, success) { features.execute(req, res, function(msg, success) {
Expand Down
25 changes: 25 additions & 0 deletions js/database.js
@@ -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;
5 changes: 3 additions & 2 deletions features.js → js/features.js
@@ -1,8 +1,9 @@
var url = require("url"), var url = require("url"),
sample_features = require("./sample_features.js"); sample_features = require("./sample_features.js");


function Features() { function Features(db) {
this.feature_list = sample_features.get_sample_feature_list(); 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.parse_url = function(url_string, parse_qs) { return url.parse(url_string, parse_qs); }


this.execute = function(req, res, callback) { this.execute = function(req, res, callback) {
Expand Down
File renamed without changes.

0 comments on commit 57a16a1

Please sign in to comment.