Skip to content

Instantly share code, notes, and snippets.

@edef1c edef1c/app.js
Created Sep 15, 2012

Embed
What would you like to do?
simple express/browserify/shoe/dnode app
var express = require('express')
var browserify = require('browserify');
var dnode = require('dnode');
var shoe = require('shoe');
var http = require('http')
var path = require('path');
var app = express();
var server = http.createServer(app)
app.configure(function() {
app.set('port', process.env.PORT || 80);
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(browserify(path.join(__dirname, 'public', 'index.js'), {
mount: '/index.js',
watch: true,
}));
app.use(express.static(path.join(__dirname, 'public')));
});
var sock = shoe(function(stream) {
var d = dnode({
meep: function(meepage, cb) {
console.log('meep! ' + meepage);
if (typeof cb == 'function') cb();
},
});
d.pipe(stream).pipe(d);
});
sock.install(server, '/dnode');
app.configure('development', function() {
app.use(express.errorHandler());
});
server.listen(app.get('port'), function() {
console.log("Express server listening on port " + app.get('port'));
});
<!DOCTYPE html>
<html>
<head>
<title>magic</title>
<script type="text/javascript" src="index.js"></script>
</head>
<body>D=</body>
</html>
var shoe = require('shoe');
var dnode = require('dnode');
var stream = shoe('/dnode');
var d = dnode();
d.on('remote', function(remote) {
remote.meep('whee', function() {
document.body.innerText = '=D';
})
});
d.pipe(stream).pipe(d);
{
"name": "magic",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express":"~3.0.0rc3",
"browserify":"~1.15.5",
"shoe":"~0.0.7",
"dnode":"~1.0.1"
},
"engines": {
"node": "0.8.x"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.