
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
/etc/hosts manipulation (in node.js)
npm install hostile
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.
hostile list
hostile set [ip] [host]
examples:
hostile set localhost domain.com
hostile set 192.168.33.10 domain.com
hostile remove [host]
example:
hostile remove domain.com
hostile load [file_path]
hosts.txt
# hosts.txt
127.0.0.1 github.com
127.0.0.1 twitter.com
example:
hostile load hosts.txt
hostile unload [file_path]
# hosts.txt
127.0.0.1 github.com
127.0.0.1 twitter.com
example:
hostile unload hosts.txt
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.
var hostile = require('hostile')
hostile.set('127.0.0.1', 'peercdn.com', function (err) {
if (err) {
console.error(err)
} else {
console.log('set /etc/hosts successfully!')
}
})
If the rule already exists, then this does nothing.
hostile.remove('127.0.0.1', 'peercdn.com', function (err) {
if (err) {
console.error(err)
} else {
console.log('set /etc/hosts successfully!')
}
})
If the rule does not exist, then this does nothing.
// If `preserveFormatting` is true, then include comments, blank lines and other
// non-host entries in the result
var preserveFormatting = false
hostile.get(preserveFormatting, function (err, lines) {
if (err) {
console.error(err.message)
}
lines.forEach(function (line) {
console.log(line) // [IP, Host]
})
})
// If `preserveFormatting` is true, then include comments, blank lines and other
// non-host entries in the result
var preserveFormatting = false
hostile.getFile(file_path, preserveFormatting, function (err, lines) {
if (err) {
console.error(err.message)
}
lines.forEach(function (line) {
console.log(line) // [IP, Host]
})
})
MIT. Copyright (c) Feross Aboukhadijeh.
FAQs
Simple /etc/hosts manipulation
The npm package hostile receives a total of 182,513 weekly downloads. As such, hostile popularity was classified as popular.
We found that hostile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.