Answers for "call node js function from javascript"

0

call node js function from javascript

var io = require('socket.io').listen(80); // initiate socket.io server

io.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' }); // Send data to client

  // wait for the event raised by the client
  socket.on('my other event', function (data) {  
    console.log(data);
  });
});
Posted by: Guest on February-21-2021
0

call node js function from javascript

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect('http://localhost'); // connec to server
  socket.on('news', function (data) { // listen to news event raised by the server
    console.log(data);
    socket.emit('my other event', { my: 'data' }); // raise an event on the server
  });
</script>
Posted by: Guest on February-21-2021

Code answers related to "call node js function from javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language