Skip to content

Commit

Permalink
THe notify.js and package.json files for node
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamrege committed Jan 28, 2012
1 parent 7db4133 commit 25169ba
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
34 changes: 34 additions & 0 deletions notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var express = require('express')
, app = express.createServer()
, io = require('socket.io').listen(app);


app.use(express.bodyParser());
app.listen(13002);

var connections = {}

/********** express.js routes ************/
app.get('/', function (req, res) {
res.send(404);
});

app.post('/message/:action/:to', function (req, res) {
target = connections[req.params.to]
if (target) {
connections[req.params.to].emit(req.params.action, req.body);
res.send(200);
}
else
res.send(404);
});

/********** socket.io work ***************/
io.sockets.on('connection', function(socket) {
socket.on('username', function(username) {
connections[username] = socket;
});

});


9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "notify.js"
, "description": "Messaging service"
, "version": "0.0.1"
, "dependencies": {
"express": "2.3.11"
, "socket.io": "0.8.5"
}
}

0 comments on commit 25169ba

Please sign in to comment.