finds.dev← search

// the find

feross/hostile

★ 796 · JavaScript · MIT · updated Dec 2024

Simple, programmatic `/etc/hosts` manipulation (in node.js)

A tiny Node.js library (and CLI) for reading and writing /etc/hosts programmatically. Useful for local dev tools, test environments, or anything that needs to redirect domains without touching DNS. Feross wrote it; it does one thing.

Sync and async APIs for the same operations — no forced callback hell when you just want a one-liner. The load/unload file commands are genuinely useful for toggling named sets of overrides (think switching between project environments). Idempotent set/remove: calling set twice doesn't duplicate the entry. Very small surface area — the whole implementation is one file, easy to audit.

No atomic writes — it reads the file, modifies it in memory, writes it back, which is a race condition if two processes touch hosts simultaneously. Doesn't handle multiple hostnames on a single IP line (the common hosts file pattern of '127.0.0.1 foo bar baz'), so it can mangle existing entries. No Windows path customization — you're stuck with the hardcoded path, which breaks in corporate environments with non-standard Windows layouts. Callback-based API with sync fallbacks is dated; no Promise interface unless you wrap it yourself.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →