socket nodejs listen code example
Example 1: how to use of socket io on a route in nodejs
app.set('socketio', io);
router.post('/getRides', function(req, res, next) {
var io = req.app.get('socketio');
io.to(
db.rides.find(function(err, docs) {
res.json(docs);
});
};
Example 2: create a web server node js w socket.io
var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
});
http.listen(3000, () => {
});