Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
    });
};
Comment

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);
    });
};
Comment

Implement socket.io in node.js application controller

//app.js or index.js
const app = express();
var http = require("http");
var server=http.createServer(app).listen(2525, (req, res) => {
  console.log("Server running on", 2525);
});
var socketIO = require("socket.io");
var io = socketIO(server);
global.io = io //Importent line

//Add the below statement to your controller code
global.io.emit("eventname", "yourdata"); //Importent line
Comment

PREVIOUS NEXT
Code Example
Javascript :: js display 
Javascript :: js create dom object 
Javascript :: substring in javascript 
Javascript :: extjs clone object 
Javascript :: jquery get element by data attribute 
Javascript :: override backswipe behaviour in ios and android react native 
Javascript :: regex city and state 
Javascript :: how to filter an array of strings to see which letters match javascript 
Javascript :: change the origin of html canvas 
Javascript :: separador de miles javascript 
Javascript :: how to add row in angular dynamically 
Javascript :: geolocation 
Javascript :: mongoose create populate response 
Javascript :: three ways of writing a function in javascript 
Javascript :: check if alpine js is loaded 
Javascript :: how to print elements in an array in javascript 
Javascript :: javascript slider 
Javascript :: set token to expiration with passport jwt. 
Javascript :: how to delete current clicked item in array react 
Javascript :: ERROR TypeError: By.Subject is not a constructor 
Javascript :: how to change currency in react-paypal-button-v2 
Javascript :: javascript typed array 
Javascript :: super in javascript 
Javascript :: sequelize exclude attributes 
Javascript :: remove shadow in jquery 
Javascript :: how to set dropdown value in textbox using jquery 
Javascript :: how to assign empty function in react component props 
Javascript :: nodejs mysql error handling with user example 
Javascript :: javascript wait to execute function on keyup 
Javascript :: express alternatives 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =