Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Notification node server
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;
});
});
@chanakaDe

This comment has been minimized.

Copy link

commented Dec 8, 2015

How can we get this using another js function ?

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.