{"id":13583402,"url":"https://github.com/feross/hostile","last_synced_at":"2025-05-14T02:07:37.088Z","repository":{"id":9577089,"uuid":"11491856","full_name":"feross/hostile","owner":"feross","description":"Simple, programmatic `/etc/hosts` manipulation (in node.js)","archived":false,"fork":false,"pushed_at":"2024-12-23T16:51:19.000Z","size":97,"stargazers_count":791,"open_issues_count":10,"forks_count":50,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-10T18:30:52.922Z","etag":null,"topics":["hosts","ip","javascript","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"cesanta/v7","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/feross.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"feross"}},"created_at":"2013-07-18T01:51:02.000Z","updated_at":"2025-03-17T18:27:14.000Z","dependencies_parsed_at":"2025-01-01T22:02:58.961Z","dependency_job_id":"b13a09b8-63d9-4ee9-97c7-801046e1967f","html_url":"https://github.com/feross/hostile","commit_stats":{"total_commits":108,"total_committers":15,"mean_commits":7.2,"dds":0.2314814814814815,"last_synced_commit":"c99539ecf4003e11a299bb2217b524764b223e76"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fhostile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fhostile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fhostile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fhostile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feross","download_url":"https://codeload.github.com/feross/hostile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052870,"owners_count":22006717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hosts","ip","javascript","nodejs"],"created_at":"2024-08-01T15:03:27.470Z","updated_at":"2025-05-14T02:07:32.071Z","avatar_url":"https://github.com/feross.png","language":"JavaScript","readme":"# hostile [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]\n\n[ci-image]: https://img.shields.io/github/workflow/status/feross/hostile/ci/master\n[ci-url]: https://github.com/feross/hostile/actions\n[npm-image]: https://img.shields.io/npm/v/hostile.svg\n[npm-url]: https://npmjs.org/package/hostile\n[downloads-image]: https://img.shields.io/npm/dm/hostile.svg\n[downloads-url]: https://npmjs.org/package/hostile\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n#### Simple, programmatic `/etc/hosts` manipulation (in node.js)\n\n![hostile](https://raw.github.com/feross/hostile/master/img.png)\n\n## install\n\n```bash\nnpm install hostile\n```\n\n## usage\n\nIf you use OS X or Linux, this module assumes your hosts file is at `/etc/hosts`. On\nWindows, it assumes your hosts file is at `C:/Windows/System32/drivers/etc/hosts`.\n\n**Commands that modify the hosts file require root privileges.**\n\n#### list all host file records\n\n```bash\nhostile list\n```\n\n#### set a domain in the hosts file\n\n```bash\nhostile set [ip] [host]\n```\n\nexamples:\n```bash\nhostile set localhost domain.com\nhostile set 192.168.33.10 domain.com\n```\n\n#### remove a domain from the hosts file\n\n```bash\nhostile remove [host]\n```\n\nexample:\n```bash\nhostile remove domain.com\n```\n\n#### load a set of hosts from a file\n\n```bash\nhostile load [file_path]\n```\nhosts.txt\n```bash\n# hosts.txt\n127.0.0.1 github.com\n127.0.0.1 twitter.com\n```\n\nexample:\n```bash\nhostile load hosts.txt\n```\n\n#### unload [remove] a set of hosts from a file\n\n```bash\nhostile unload [file_path]\n```\n\n```bash\n# hosts.txt\n127.0.0.1 github.com\n127.0.0.1 twitter.com\n```\n\nexample:\n```bash\nhostile unload hosts.txt\n```\n\n## methods\n\nCommands that modify the hosts file require root privileges.\n\nI wouldn't recommend running your production node server with admin privileges unless you\ndowngrade to a normal user with\n[`process.setuid(id)`](http://nodejs.org/api/process.html#process_process_setuid_id)\nbefore you start accepting requests.\n\n**All methods have sync versions. Just omit the callback parameter.**\n\n#### add a rule to /etc/hosts\n\n```js\nvar hostile = require('hostile')\nhostile.set('127.0.0.1', 'peercdn.com', function (err) {\n  if (err) {\n    console.error(err)\n  } else {\n    console.log('set /etc/hosts successfully!')\n  }\n})\n```\n\nIf the rule already exists, then this does nothing.\n\n#### remove a rule from /etc/hosts\n\n```js\nhostile.remove('127.0.0.1', 'peercdn.com', function (err) {\n  if (err) {\n    console.error(err)\n  } else {\n    console.log('set /etc/hosts successfully!')\n  }\n})\n```\n\nIf the rule does not exist, then this does nothing.\n\n#### get all lines in /etc/hosts\n\n```js\n// If `preserveFormatting` is true, then include comments, blank lines and other\n// non-host entries in the result\nvar preserveFormatting = false\n\nhostile.get(preserveFormatting, function (err, lines) {\n  if (err) {\n    console.error(err.message)\n  }\n  lines.forEach(function (line) {\n    console.log(line) // [IP, Host]\n  })\n})\n```\n\n#### get all lines in any file\n\n```js\n// If `preserveFormatting` is true, then include comments, blank lines and other\n// non-host entries in the result\nvar preserveFormatting = false\n\nhostile.getFile(file_path, preserveFormatting, function (err, lines) {\n  if (err) {\n    console.error(err.message)\n  }\n  lines.forEach(function (line) {\n    console.log(line) // [IP, Host]\n  })\n})\n```\n\n## contributors\n\n- [Feross Aboukhadijeh](http://feross.org) (author)\n- [Maayan Glikser](https://github.com/morsdyce)\n\n## license\n\nMIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).\n","funding_links":["https://github.com/sponsors/feross"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fhostile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeross%2Fhostile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fhostile/lists"}