I'm creating a small npm Pomodoro timer project. When I start the project, it starts a timer, and added a list of websites to /etc/hosts
file, when I terminate the project, that list is removed.
My code works
// all the variables
let OriginalfileContents, all
// console.log( blockedWebsites')
fs.readFile(filePath, (err, data) => {
OriginalfileContents = data.toString()
all = OriginalfileContents + blockedWebsites
fs.writeFileSync(filePath, all , 'utf-8');
})
function exitHandler(options, exitCode) {
if (options.cleanup) console.log('clean');
if (exitCode || exitCode === 0) {
var all = OriginalfileContents + blockedWebsites
fs.writeFileSync(filePath, OriginalfileContents , 'utf-8');
}
if (options.exit) process.exit();
}
process.on('exit', exitHandler.bind(null,{cleanup:true}));
process.on('SIGINT', exitHandler.bind(null, {exit:true}));
So upon sudo node blocker.js
, /etc/hosts
get the following
127.0.0.1 facebook.com
127.0.0.1 www.facebook.com
127.0.0.1 quora.com
127.0.0.1 www.quora.com
And when I control c, those lines are removed.
I there a way to get chrome to read the changes without closing the entire browser