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).
- Is it possible?
- Is it a good practice?
- Have you got an advice for such a situation?
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'); 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.
[email protected], I want it be that and always be that until I purposefully install the next version.