Answers for "how to use of socket io on a route in nodejs"

0

how to use of socket io on a route in nodejs

//Using Express 4, in your app.js file you can use
app.set('socketio', io);

//then in your router you can access it like this
router.post('/getRides', function(req, res, next) {
    var io = req.app.get('socketio');

    io.to(//socket.id//).emit("message", data);

    db.rides.find(function(err, docs) {
        res.json(docs);
    });
};
Posted by: Guest on August-23-2020
0

how to use of socket io on a route in nodejs

router.post('/getRides', function(req, res, next) {
    var io = req.app.get('socketio');

    io.to(//socket.id//).emit("message", data);

    db.rides.find(function(err, docs) {
        res.json(docs);
    });
};
Posted by: Guest on August-23-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language