Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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

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>
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to sort string alphabetically in javascript 
Javascript :: Child nodes in a node 
Javascript :: how to take last element of array javascript 
Javascript :: express router 
Javascript :: heap javascript 
Javascript :: jq json 
Javascript :: javascript comment 
Javascript :: Query MongoDB - Node.js 
Javascript :: javascript debugging 
Javascript :: async vs await javascript 
Javascript :: context api in react 
Javascript :: js map on object 
Javascript :: react native update helper 
Javascript :: counting pairs in an array, resulting in a given sum 
Javascript :: javascript prototype inheritance 
Javascript :: react router refreshes page 
Javascript :: react tutorial 
Javascript :: how to check if a number is negative in p5.js 
Javascript :: Div draggable x axe only 
Javascript :: aria labelledby js 
Javascript :: java jsp attribute qualified names must be unique within an element 
Javascript :: alert on right click jquery 
Javascript :: angular generer guard 
Javascript :: object for loop 
Javascript :: excluding a attribute from json strigify 
Javascript :: tinymce image and links inputs disabled 
Javascript :: nodejs json data serving 
Javascript :: predicate logic solver 
Javascript :: { "data": [ { "title": "", "img": "", "address": "" }, ] } json to html 
Javascript :: PlayerInteractEntityEvent get called twice 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =