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

3.75
4
Rob Johansen 105 points

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

3.75 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
add socket io to node js example get socket io in route listen to socket.io routes express socket.io routes express connect socket io with nodejs socket io in nodejs express for real time node js with socket io node js how to use socket.io socket.io and express router socket.io js and routers how to create use in socket io with express js how to add socket io to ur node app socket.io with express router how to use socket io with nodejs do i need to create route in socket io implement socket.io in nodejs how to use socket io with express use socket.io in nodejs add socket io to express route socket routing node js node js for client socket io socket io node js routers socket.io in express routes use socket.io with express routes socket io routes how is socket.io different from express routing using socket.io with express routing socket.io express router socket io setup in expressjs how to setup socket io in nodejs use socket io inside an api route express socket io in express router How do I use a socket IO client in node? how to use router with socket.io use socket io inside a route in express node route socket.io use socket io in an express app how to use node socket io in real time app example how to use of socket io on a route in node js why use socket io in routes of express js why use socket io in routes of expressjs how to use of socket io on a route in nodejs how to use socket.io in express js with router nodejs socketio router express 4 socket.io with router nodejs socket.io with router node js socket.io with browser connect api app to socket.io node.js How to work nodejs with socket io? how to get location with socket.io in node js routing socket io express configuring socket io in node js sockets.io nodejs by using socket getting socket.io in route socket.io connect nodejs socket io io instance in express routes socket io express router socket io express ro make socket.io socket from noejs make a socket.io socket in nodejs nodejs socket io on specific route only call socket io in nodejs socket io + express route how to use socket.io in nodejs socket.io router express socket io with route socket io node make connect from node.js node js socket how to use socket.io through get in express use socket.io in route using sockets.io with node node js web how to use socket io using socket.io in express route socket node js listen socket nodejs listen chat socket.io express vue socket io socket io setting with node.js express socket io on route socket io with express router how to use socket io in nodejs socket io in express routes nodejs set up socket io using socket.io in express how to connect node js with socket io how to use socket.io in routes socket.io nodejs routes socket io connect to express route how to create different routes in socket.io application how to use socket.io in different routes of expressjs best way to implement socket io in node.js using routes in nodejs for socketio sockets or routes nodejs node js sockets vs routes setting route inside socket express router with socket io sockets on expres router socket io on certain routes use socket io in routes node.js socket.io express router how to use socket.io in express routes socketio how to accept any route express router socket.io Using Socket.io in routes io socket connections on node routes use socket.io with routes
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source