hosts-etc
hosts-etc
is your friendly neighbourhood host file editor for use within Node! Maybe one day it'll be a command line tool, but don't place too many bets!
What it can do though, is make it look like the hosts file is organised through regions and host comments.
Installation
$ npm install --save hosts-etc
Usage
const hosts = require('hosts-etc');
const pHosts = hosts.promise;
let aCoolHost = new hosts.Host("127.5.5.5", "localhost");
console.log(hosts.get());
console.log(hosts.get("# region"));
console.log(hosts.get("g(oo)gle"))
console.log(hosts.get("127.x.4.x"));
let address = "127.3.3.3";
let host = "hostman";
let opts = {
comment: "Check out hostman! That project depends on this one!",
region: "hostman"
}
hosts.set(aCoolHost);
hosts.set(address, host, opts);
let mcWorlds = [
{
address:"192.168.0.10",
host:"my.mc.world",
region: "mc worlds",
comment: "My Minecraft world!"
},
new hosts.Host(
"192.168.0.20",
"their.mc.world", {
region: "mc worlds",
comment: "Their Minecraft world!"
}
)
];
hosts.set(mcWorlds);
hosts.remove("#mc worlds");
hosts.useCache(false);
hosts.useCache();
Regions
Regions make managing your hosts file a whole bunch eaiser! The idea is that similar host entries go into the same region so that when you do a host lookup/delete, you have some ballpark idea of where to look. It also allows other programs to take care of their own regions, just like hostman does!
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate. Yeah.... We'll get to testing one day... Maybe you could sort it out? 🙏
License
MIT