I have the following back-end with socket.io
. Each time we open a connection by localhost:3000
in a new browser tab, a file named with the socket id is created in the folder tmp/
of the server.
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!');
});
});
Because sockets may be disconnected, inactive or idle later. I want to set a simple cleaning rule in the server. For example, at 4pm
of everyday, I want to delete all the files that were saved before 4pm
of yesterday.
So does anyone know how to set up this regular checking+deletion every day?
Edit 1: 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 network code within the website nodejs code (though the nodejs code may call external bash).