title: A regular checking and cleaning of files in the server
body: <p>I have the following back-end with <code>socket.io</code>. Each time we open a connection by <code>localhost:3000</code> in a new browser tab, a file named with the socket id is created in the folder <code>tmp/</code> of the server.</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var server = require('http').createServer(app);
  var io = require('socket.io').listen(server);
  
  server.listen(3000);
  
  app.get('/', function (req, res) {
      res.sendfile(__dirname + '/index.html');
  });
  
  io.sockets.on('connection', function(socket) {
      var fs = require('fs');
      fs.writeFile("tmp/" + socket.id, "hello", function (err) {
          if (err) { return console.log(err) };
          console.log('a file is saved!');
      });
  });
  </code></pre>
  
  <p>Because sockets may be disconnected, inactive or idle later. I want to set a simple cleaning rule in the server. For example, <strong>at <code>4pm</code> of everyday, I want to delete all the files that were saved before <code>4pm</code> of yesterday.</strong></p>
  
  <p>So does anyone know how to set up this regular checking+deletion every day?</p>
  
  <p><strong>Edit 1:</strong> Following the discussion with @georoot , I realise I need to send a notification message to the connections whose tmp file was just removed. And I would prefer to have all the <strong>network</strong> code within the website nodejs code (though the nodejs code may call external bash).</p>