Skip to content

Commit

Permalink
Merge pull request #5 from jamesor/master
Browse files Browse the repository at this point in the history
option7_node_socketio
  • Loading branch information
addyosmani committed May 6, 2012
2 parents 1950dd1 + 54f081c commit f696e00
Show file tree
Hide file tree
Showing 19 changed files with 1,252 additions and 0 deletions.
2 changes: 2 additions & 0 deletions option7_node_socketio/.gitignore
@@ -0,0 +1,2 @@
node_modules
public/stylesheets/*.css
72 changes: 72 additions & 0 deletions option7_node_socketio/README.md
@@ -0,0 +1,72 @@
# TodoMVC

#### A common demo application for popular JavaScript MV* frameworks

## Introduction

This demo was written to illustrate how a server-side JavaScript solution could be applied to the TodosMVC application using sockets.

#### Technologies Used In This Demo

- [Underscore.js](http://documentcloud.github.com/underscore/) - A utility-belt library for JavaScript without extending any of the built-in JavaScript objects.
- [Backbone.js](http://documentcloud.github.com/backbone/) - Gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
- [backbone.iobind](https://github.com/logicalparadox/backbone.iobind) - Bind socket.io events to backbone models & collections. Also includes a drop-in replacement for Backbone.sync using socket.io.
- [jQuery](http://jquery.com/) - A fast, concise, library that simplifies how to traverse HTML documents, handle events, perform animations, and add AJAX.
- [Node.js](http://nodejs.org/) - Event-driven I/O server-side JavaScript environment based on V8.
- [Express](http://expressjs.com/) - High performance, high class web development for node.js.
- [Jade](http://jade-lang.com/) - High performance template engine heavily influenced by Haml and implemented with JavaScript for node.js.
- [Stylus](http://learnboost.github.com/stylus/) - Expressive, dynamic, robust CSS for node.js
- [Socket.io](http://socket.io/) - Aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. It's care-free realtime 100% in JavaScript.
- [Mongoose](http://mongoosejs.com/) - A MongoDB object modeling tool designed to work in an asynchronous environment.
- [MongoDB](http://www.mongodb.org/) - A scalable, high-performance, open source NoSQL database.
- [Redis](http://redis.io/) - an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

## Getting the Demo

1. Fork this repo by clicking the "Fork" button above
2. Clone your fork to make a local working copy. For example:
<pre>
$ git clone git@github.com:[your_github_username]/backbone-boilerplates.git
$ cd backbone-boilerplates/option7_node_socketio
</pre>

## Setting up Dependencies

1. Install [node.js](http://nodejs.org/#download).
2. Install [MongoDB](http://www.mongodb.org/downloads).
3. Start the MongoDB server from a terminal window:
<pre>
$ mongod
</pre>
4. Install [Redis](http://redis.io/download).
5. Start the Redis Server from another terminal window:
<pre>
$ redis-server
</pre>
6. Make sure your current directory is option7_node_socketio before step 7.
<pre>
$ pwd
[your repos path]/backbone-boilerplates/option7_node_socketio
</pre>
7. Install dependencies using the node package manger (npm).
<pre>
$ sudo npm link
</pre>

## Running the Demo

1. Start the Todos demo server from a different terminal window:
<pre>
$ node app
</pre>
2. Visit [http://localhost:3000](http://localhost:3000) in a web browser.

## Credit

- [Jérôme Gravel-Niquet](http://jgn.me/) - Created original demo
- [Addy Osmani](http://addyosmani.com/) - Cleanup, edits
- [James O'Reilly](http://jamesor.com/) - Added server-side tech from node.js to MongoDB.

## License

Public Domain
42 changes: 42 additions & 0 deletions option7_node_socketio/app.js
@@ -0,0 +1,42 @@
var express = require('express')
, mongoose = require('mongoose')
, todo = require('./models/todo')
, routes = require('./routes')
, sockets = require('./sockets')
, connect = require('express/node_modules/connect')
, RedisStore = require('connect-redis')(express)
, sessionStore = new RedisStore()
, app = express.createServer()
, sio;

app.configure(function () {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(require('stylus').middleware({ src: __dirname + '/public' }));
app.use(express.static(__dirname + '/public'));
app.use(express.cookieParser('keyboard cat'));
app.use(express.session({
secret: 'keyboard cat',
key: 'express.sid',
store: sessionStore
}));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
});

app.configure('development', function () {
app.use(express.errorHandler());
});

routes.init(app);
mongoose.connect("127.0.0.1", "todomvc", 27017);

app.listen(3000);

sio = require('socket.io').listen(app);
sockets.init(sio, sessionStore);

console.log("Express server listening on port 3000");
16 changes: 16 additions & 0 deletions option7_node_socketio/models/todo.js
@@ -0,0 +1,16 @@
(function (module) {

"use strict";

var mongoose = require('mongoose')
, TodoSchema;

TodoSchema = new mongoose.Schema({
title: { 'type': String, 'default': 'empty todo...' },
order: { 'type': Number },
done: { 'type': Boolean, 'default': false }
});

module.exports = mongoose.model('Todo', TodoSchema);

}(module));
18 changes: 18 additions & 0 deletions option7_node_socketio/package.json
@@ -0,0 +1,18 @@
{
"name": "todos-backbone-node-sockets-lock",
"author": "James O'Reilly",
"version": "0.0.2",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "2.5.6",
"jade": "*",
"mongoose": "*",
"stylus": "*",
"socket.io": "*",
"redis": "*",
"connect-redis": "*"
}
}
Binary file added option7_node_socketio/public/images/destroy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f696e00

Please sign in to comment.