You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simple, programmatic /etc/hosts manipulation (in node.js)
install
npm install hostile
usage
If you use OS X or Linux, this module assumes your hosts file is at /etc/hosts. On
Windows, it assumes your hosts file is at C:/Windows/System32/drivers/etc/hosts.
Commands that modify the hosts file require root privileges.
list all host file records
hostile list
set a domain in the hosts file
hostile set [ip] [host]
examples:
hostile set localhost domain.com
hostile set 192.168.33.10 domain.com
Commands that modify the hosts file require root privileges.
I wouldn't recommend running your production node server with admin privileges unless you
downgrade to a normal user with
process.setuid(id)
before you start accepting requests.
All methods have sync versions. Just omit the callback parameter.
If the rule does not exist, then this does nothing.
get all lines in /etc/hosts
// If `preserveFormatting` is true, then include comments, blank lines and other// non-host entries in the resultvarpreserveFormatting=falsehostile.get(preserveFormatting,function(err,lines){if(err){console.error(err.message)}lines.forEach(function(line){console.log(line)// [IP, Host]})})
get all lines in any file
// If `preserveFormatting` is true, then include comments, blank lines and other// non-host entries in the resultvarpreserveFormatting=falsehostile.getFile(file_path,preserveFormatting,function(err,lines){if(err){console.error(err.message)}lines.forEach(function(line){console.log(line)// [IP, Host]})})