Back to Browse

Blocking websites with Node.js on a MAC and Windows inside an Electron.js application

1.6K views
Jan 25, 2020
24:14

Blocking websites on a Mac and Windows is surprisingly easy to do, and it is a unified API across all Operating Systems. On each OS there is a file called "hosts", where we have a record for telling our network driver which IP address should be used for specific domain names. That usually helps when we want, for example, test our Web application similar to the production environment, but on our laptops by pointing our main domain name to our local IP address 127.0.0.1 . The actual record looks something like this .... 127.0.0.1 facebook.com .... When we are trying to make an HTTP request our OS reads this file, locates [facebook.com](http://facebook.com) domain name and picks up the IP address that we have in front of that, instead of making a full DNS resolve cycle. For our use-case, we are going to make this kind of records automatically Using Node.js and TypeScript, to point all domain names in our BlackList to 127.0.0.1 which is obviously going to fail website navigation for that domain names, because we don't have that website or any other webserver available on HTTP or HTTPS ports.

Download

0 formats

No download links available.

Blocking websites with Node.js on a MAC and Windows inside an Electron.js application | NatokHD