title: How to send variables from Node.js to Socket.io and display on local webpage?
body: <p>I'm working on a project where my job is to use Node.js and Socket.io to read a text file (contain 3 real time readings) and got the data in 3 variables, then send them to Socket.io and get them displayed on the website continuously without having to refresh it. I ran my codes, it did not give any errors, but it did not display anything on the website either. So I don't know what is wrong in my code. I need help with passing variables from Node.js to Socket.io and get them displayed on the my web page. 
  This is my server file: </p>
  
  <pre><code>var http = require('http').createServer(handler); //require http server, and cr$
  var fs = require('fs'); //require filesystem module
  var io = require('socket.io')(http) //require socket.io module and pass the htt$
  
  http.listen(8080); //listen to port 8080
  function handler (req, res) { //create server
    fs.readFile(__dirname + '/index.html', function(err, data) { //read file inde$
      if (err) {
        res.writeHead(404, {'Content-Type': 'text/html'}); //display 404 on error
        return res.end("404 Not Found");
      }
      res.writeHead(200, {'Content-Type': 'text/html'}); //write HTML
      res.write(data); //write data from index.html
      return res.end();
    });
  }
  io.sockets.on('connection', function (socket) {
     setInterval(function(){
     var array = fs.readFileSync('report.txt').toString().split("\n");
     var volt = (array[0]);
     var power = (array[1]);
     var temp = (array[2]);
     socket.emit('volt',{'volt': volt});
     socket.emit('power',{'power': power});
     socket.emit('temp',{'temp': temp});
     }, 1000);
  });
  </code></pre>
  
  <p>index.html file :</p>
  
  <pre><code>&lt;body&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"&gt;&lt;/script&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    var socket = io('http://10.117.230.219:8080');
    socket.on('volt', function (data) {
      $('#volt').text(data.volt);
    socket.on('power', function (data) {
      $('#power').text(data.power);
    socket.on('temp', function (data) {
      $('#temp').text(data.temp);
      });
  &lt;/script&gt;
     &lt;div id="volt"&gt;&lt;/div&gt;
     &lt;div id="power"&gt;&lt;/div&gt;
     &lt;div id="temp"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>