Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Node.js MVC: Express.js and Derby Hello World Tutorial
<Body:>
<input value="{message}"><h1>{message}</h1>
var derby = require('derby'),
app = derby.createApp(module);
app.get('/', function(page, model, params) {
model.subscribe('message', function() {
page.render();
})
});
app.ready(function(model) {
model.on('set', 'message', function(path, object) {
console.log('message has been changed: ' + object);
})
});
h1 {
color: blue;
}
var http = require('http'),
express = require('express'),
derby = require('derby'),
derbyApp = require('./derby-app');
var expressApp = new express(),
server = http.createServer(expressApp);
var store = derby.createStore({
listen: server
});
var model = store.createModel();
expressApp.
use(store.modelMiddleware()).
use(express.static(__dirname + '/public')).
use(derbyApp.router()).
use(expressApp.router);
server.listen(3001, function(){
model.set('message', 'Hello World!');
store.afterDb('set','message', function(txn, doc, prevDoc, done){
console.log(txn)
done();
})
});
{
"name": "DerbyTutorial",
"description": "",
"version": "0.0.0",
"main": "./server.js",
"dependencies": {
"derby": "*",
"express": "3.x"
},
"private": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment