var ws = require('ws');
var fs = require('fs');
var https = require('https');
var options = {
server : https.createServer({
cert : fs.readFileSync('/path/to/crt'),
key : fs.readFileSync('/path/to/key'),
}).listen(2000)
};
var timeout;
fs.watch('/path/to/crt', () => {
clearTimeout(timeout);
timeout = setTimeout(() => {
options.server._sharedCreds.context.setCert(fs.readFileSync('/path/to/crt'));
options.server._sharedCreds.context.setKey(fs.readFileSync('/path/to/key'));
}, 1000);
});
new ws.Server(options);
...maybe incited of timeout is better to use _.debaunce
Anything older than 7 days should be deleted.!
const fs = require('fs');
const path = require('path');
const dirname = path.join(__dirname, 'files');
const files = fs.readdirSync(dirname);
const ms1Day = 24*60*60*1000;
files.forEach(file => {
const filePath = path.join(dirname, file);
fs.stat(filePath, (err, stats) => {
if (err) throw err;
if ((Date.now() - stats.mtime.getTime() > 7*ms1Day)) {
fs.unlink(filePath, (err) => {
if (err) throw err;
console.log(`deleted ${filePath}`);
});
}
});
});
pluralsight jscomplete/advanced-nodejs course files
<- good and free!