title: How to include node.js to static html
body: <p>I'm trying to do API in javascript for another users. I want to create a chat in realtime in Node.js with socket.io but I want to give the opportunity loading this API in common HTML through javascript. For example, if somebody copy and paste simple js script into your html, then chat is loaded.</p>
  
  <p>My app is running in node on port 8080 and my other page is html on port 80.
  How can I put node.js in other page?</p>
  
  <p>below is my chat.js</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var http = require('http').Server(app);
  var io = require('socket.io')(http);
  
  var cors = require('cors');
  
  app.use(cors());
  app.options('*', cors());
  
  app.get('/', function(req, res){
    res.sendFile(__dirname + '/index.html');
  
  });
  
   io.on('connection', function(socket){
  
   console.log('a user connected');
  
     socket.on('chat message', function(msg){
     console.log('the user wrote:' +msg);
     io.emit('chat message', msg, id);
  
     });
  
   });
  
   http.listen(8080, function(){
    console.log('listening on *:8080');
   });
  </code></pre>
  
  <p>In this way I try to load:</p>
  
  <pre><code>&lt;script&gt;
    $.ajax({
  
        xhrFields: {
            withCredentials: true
        },
        dataType: "html",
        url: "http://127.0.0.1:8080/index.js"
  
     }).done(function(data){
  
     // next function here;
  
     });
  &lt;/script&gt;
  </code></pre>