Reputation: 8668
I'm working on an updater and I wish there is some way for the updater to update itself (remove and copy the new file from which the script is run).
Upvotes: 4
Views: 997
Reputation: 2810
Example:
var fs = require('fs');
console.log("I'm about to delete myself...");
console.log('clonning myself...');
fs.copyFileSync('./selfDelete.js', './selfDelete_bkp.js');
console.log('removing myself...');
fs.unlinkSync('./selfDelete.js');
console.log('new version of me...');
fs.renameSync('./selfDelete_bkp.js', './selfDelete.js');
Upvotes: 4
Reputation: 959
Not a good practice.
And you cannot update while you running. What I can suggest is you can create a new file somewhere with updates and then replace the current file with the new file from a scheduled task which runs sometime later. Not sure that answered your question but this is what I can think of.
Upvotes: 1