Created
May 7, 2013 04:48
-
-
Save azat-co/5530311 to your computer and use it in GitHub Desktop.
Node.js MVC: Express.js and Derby Hello World Tutorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Body:> | |
| <input value="{message}"><h1>{message}</h1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| }) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| h1 { | |
| color: blue; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| }) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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