I use node.js
to load dynamic crontab to to operation system
and I want to add close function that when I close the node.js
server it call this function and remove all the crontabs
Code:
var server = app.listen(8080, function() {
loadCronTab("*/1 * * * * date");
console.log('Server running...');
});
server.on('close', function () {
closeCronTab();
console.log("Closed");
redis.quit();
});
The remove function is:
function closeCronTab()
{
require('crontab').load(function(err, crontab) {
if (err) {
return console.error(err);
}
var command = 'ls -l';
crontab.remove({command:command});
crontab.save(function(err, crontab) {
});
});
}
I have use var express with my node.js
it can help?
I don't know how to write the close function syntax.. =(
I try
var server = app.listen(8080, function() {
console.log('Server running...');
});
server.close(function(){
closeCronTab();
console.log("Closed");
});
But it runs the server and closes it after a second..