Search code examples
node.jsexpressembedreal-time

how to embed nodejs application on client website?


firstly sorry for not standard English. : D

I have a chat application using nodejs, expresss finished running on port 3000. So I want to embed in website application clients, then how?

I had to use ajax load, but can not be:

jQuery.ajax({
  type:"GET",
  url:"http://localhost:3000/client/",
  success: function (data){
    jQuery('body').append(data);
  }
});

Solution

  • Since you are using socket.io at server side then you can get its reference at the client using below line (jquery required):

    $.getScript(host+'socket.io/socket.io.js', function() 
    {
      var clientSocket = io.connect(host);
      // ... do other stuff with your socket
    });  
    

    Where host is your server host name e.g. http://192.168.1.5:3000/ where your nodejs application is deployed.
    For more information see here for more client - server communication exposed events.