Created
March 29, 2012 08:36
-
-
Save dshaw/2235044 to your computer and use it in GitHub Desktop.
Socket.io / Express App REPL
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 express = require('express') | |
, repl = require('./repl'); | |
var app = express.createServer(); | |
app.get('/', function(req, res){ | |
res.send('Hello World'); | |
}); | |
app = repl(app); | |
app.listen(9000); |
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
/*! | |
* Socket.io / Express App REPL | |
*/ | |
/** | |
* Module dependencies. | |
*/ | |
var colors = require('colors') | |
, net = require('net') | |
, repl = require('repl'); | |
/** | |
* App | |
*/ | |
module.exports = function (app) { | |
var settings = app.set('settings') | |
, rs; | |
var server = net.createServer(function (socket) { | |
var rs = repl.start('repl> ', socket) | |
, context = rs.context; | |
context.app = app; | |
socket.on('connect', function () { | |
socket.write('\n'); | |
socket.write(('\n App REPL. Connected.').cyan); | |
socket.write('\n hint: try accessing the "app" object.'.magenta); | |
socket.write('\n hint: type "> .exit" at any point exit.'.magenta); | |
socket.write('\n\n'); | |
rs.displayPrompt(); | |
}); | |
}); | |
server.listen.apply(server, settings.repl); | |
server.on('listen', function () { | |
app.log.warn(Date.now(), 'repl started on '); | |
}); | |
return app; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment