title: auto reload browser when file content changed, saved in nodejs
body: <p>I have been working on <code>node.js</code> project. my requirement is I want to load.txt file on browser. when I change and save this file, content should be updated. Browser should be auto refresh.</p>
  
  <pre><code>    var app = require('express')();
      var http = require('http').Server(app);
      var io = require('socket.io')(http);
  
      index.js
      app.get('/', function(req, res){
        res.sendFile(__dirname + '/demo.txt');
      });
  
      io.on('connection', function(socket){
        console.log('a user connected');
      });
  
      http.listen(3000, function(){
        console.log('listening on *:3000');
      });
  
      var io = require('socket.io')(80);
      var fs = require('fs');
  
      fs.watchFile('message.text', (curr, prev) =&gt; {
        console.log(`the current mtime is: ${curr.mtime}`);
        console.log(`the previous mtime was: ${prev.mtime}`);
        // file changed push this info to client.
        io.emit('fileChanged', 'yea file has been changed.');
      });
  
      index.html
      &lt;script&gt;
        var socket = io();
      socket.on('fileChanged', function(msg){
        alert(msg);
      });
  </code></pre>