@tabcat/watchlist
v1.0.0
Published
reads a newline-delimited file into a live Set<string> that stays in sync as the file changes
Readme
@tabcat/watchlist
Reads a newline-delimited text file into a Set<string> and keeps it live as the file changes.
Useful for hot-reloadable allowlists, blocklists, peer ID lists, IP lists, or any collection of strings that operators need to edit without restarting a process.
Install
npm install @tabcat/watchlistUsage
import { watchlist } from "@tabcat/watchlist";
const { set, ready, stop } = watchlist("/etc/myapp/allowlist.txt");
// ready resolves once the file watcher is active
await ready;
// set is populated from the current file contents and stays in sync as the file is edited, created, or deleted
console.log(set.has("some-entry")); // true / false
// ...
// stop the watcher when done
await stop();The file is expected to have one entry per line. Blank lines and leading/trailing whitespace are ignored. If the file does not exist, the set starts empty and will populate if the file is created later.
API
See the API docs for full reference.
