hosts file parser
var fs = require('fs');
var Hosts = require('hosts-parser').Hosts;
var hosts = new Hosts(fs.readFileSync('/etc/hosts', 'utf8'));
console.log(hosts.toJSON());
/**
[
{
"ip": "127.0.0.1",
"hostname": "localhost"
}
]
**/
console.log(hosts.resolve('localhost'));
// 127.0.0.1
var file = fs.readFileSync('/etc/hosts', 'utf-8');
var hosts = new Hosts(file);
// or (new Hosts()).parse(file);
// return a parsed Hosts object
hosts.resolve(hostname);
// return the ip or undefined
hosts.toJSON();
// return a json formatted object
the MIT License.