The Watch API provides programmatic access to file system watchers with real-time event delivery via Server-Sent Events (SSE) and WebSocket streams. Use these endpoints to create watchers that monitor files and directories, retrieve historical events, subscribe to live event streams, and manage watcher lifecycle.
Returns service health information including process ID, uptime, IP, file descriptor count, and memory usage.
This endpoint takes no parameters.
curl https://api.example.com/api/v1/watch/health
const health = await client . watch . health . check ();
"started" : " 2026-02-11T14:00:00Z " ,
"built" : " 2026-02-10T22:15:00Z " ,
"userAgent" : " node-watcher/1.2.3 " ,
Creates a new file system watcher with the specified paths and configuration.
Name Type Required Description pathsarray Yes Absolute or relative filesystem paths to watch. coalesce_msinteger | null No Coalescing window in milliseconds. excludearray | null No Optional exclude glob patterns. Excludes take precedence over includes. history_sizeinteger | null No Replay history capacity for this watcher. ignore_dirsarray | null No Directory names or subdirectory paths to skip entirely. Pass empty array to disable the default ignore list. includearray | null No Optional include glob patterns. If present, path must match one include. kindsarray | null No Optional event kind filter. Allowed values: created, modified, removed, renamed, metadata, overflow, other. recursiveboolean | null No Recursive mode. Defaults to server config value. skip_hiddenboolean | null No When true, hidden directories are never watched or scanned into. Defaults to the server’s --default-skip-hidden.
curl -X POST https://api.example.com/watchers \
-H " Content-Type: application/json " \
"paths": ["/srv/data/uploads", "/srv/data/exports"],
"kinds": ["created", "modified", "removed", "renamed"],
"ignore_dirs": ["node_modules", ".git", "target"],
"include": ["**/*.csv", "**/*.json"],
"exclude": ["**/tmp/**"],
const watcher = await client . watch . watchers . create ( {
paths: [ " /srv/data/uploads " , " /srv/data/exports " ] ,
kinds: [ " created " , " modified " , " removed " , " renamed " ] ,
ignore_dirs: [ " node_modules " , " .git " , " target " ] ,
include: [ " **/*.csv " , " **/*.json " ] ,
"id" : " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e " ,
"created_at" : " 2026-02-11T15:30:00Z " ,
"paths" : [ " /srv/data/uploads " , " /srv/data/exports " ],
"include" : [ " **/*.csv " , " **/*.json " ],
"exclude" : [ " **/tmp/** " ],
"ignore_dirs" : [ " node_modules " , " .git " , " target " ],
"kinds" : [ " created " , " modified " , " removed " , " renamed " ],
"history_limit_bytes" : 16777216
"code" : " INVALID_REQUEST " ,
"message" : " path list cannot be empty "
Error Code Title Description Resolution INVALID_REQUESTInvalid request Request payload failed validation Check request fields and retry INVALID_PAGINATIONInvalid pagination Page or limit is out of range Use page ≥ 1 and limit between 1 and 200
"code" : " LIMIT_EXCEEDED " ,
"message" : " watcher limit reached "
Error Code Title Description Resolution LIMIT_EXCEEDEDResource limit exceeded Watcher or path limits exceeded Reduce paths or delete unused watchers HISTORY_GAPReplay history gap Requested since_id is older than retained replay history Reconnect without since_id or increase history_memory_limit_bytes
"code" : " WATCHER_START_FAILED " ,
"message" : " failed to start watcher: ... "
Error Code Title Description Resolution WATCHER_START_FAILEDWatcher startup failed Backend failed to initialize file watcher Check path permissions and kernel watch limits
Lists all file system watchers with pagination.
Name In Type Required Description pagequery integer No Page number (1-based). limitquery integer No Items per page (1-200).
curl " https://api.example.com/watchers?page=1&limit=50 "
const page = await client . watch . watchers . listIterator ( {
"id" : " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e " ,
"created_at" : " 2026-02-11T15:30:00Z " ,
"paths" : [ " /srv/data/uploads " ],
"ignore_dirs" : [ " node_modules " , " .git " ],
"kinds" : [ " created " , " modified " , " removed " , " renamed " , " metadata " , " overflow " , " other " ],
"history_limit_bytes" : 8388608
"events_broadcast" : 12475 ,
"code" : " INVALID_PAGINATION " ,
"message" : " Limit must be between 1 and 200 "
Error Code Title Description Resolution INVALID_REQUESTInvalid request Request payload failed validation Check request fields and retry INVALID_PAGINATIONInvalid pagination Page or limit is out of range Use page ≥ 1 and limit between 1 and 200
Retrieves details for a specific watcher.
Name In Type Required Description idpath string Yes Watcher id
curl https://api.example.com/watchers/9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e
const watcher = await client . watch . watchers . get ( {
id: " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e "
"id" : " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e " ,
"created_at" : " 2026-02-11T15:30:00Z " ,
"paths" : [ " /srv/data/uploads " ],
"ignore_dirs" : [ " node_modules " , " .git " ],
"kinds" : [ " created " , " modified " , " removed " , " renamed " , " metadata " , " overflow " , " other " ],
"history_limit_bytes" : 8388608
"events_broadcast" : 12475 ,
"code" : " WATCHER_NOT_FOUND " ,
"message" : " Watcher not found "
Error Code Title Description Resolution WATCHER_NOT_FOUNDWatcher not found No watcher exists for provided id List watchers and use a valid watcher id
Deletes a watcher and releases its resources.
Name In Type Required Description idpath string Yes Watcher id
curl -X DELETE https://api.example.com/watchers/9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e
const result = await client . watch . watchers . delete ( {
id: " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e "
"id" : " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e " ,
"code" : " WATCHER_NOT_FOUND " ,
"message" : " Watcher not found "
Error Code Title Description Resolution WATCHER_NOT_FOUNDWatcher not found No watcher exists for provided id List watchers and use a valid watcher id
Retrieves paginated historical events for a watcher. Supports replay semantics via since_id or since_timestamp cursors.
Name In Type Required Description idpath string Yes Watcher id since_idquery integer No Replay events strictly after this event id. since_timestampquery string No Replay events strictly after this timestamp. Accepted formats: RFC3339 (e.g. 2026-02-11T15:30:00Z), Unix seconds (e.g. 1739287800), Unix milliseconds (e.g. 1739287800123). pagequery integer No Page number (1-based). limitquery integer No Items per page (1-200).
curl " https://api.example.com/watchers/9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e/events?since_id=1000&limit=100 "
const events = await client . watch . streams . listEventsIterator ( {
id: " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e " ,
"watcher_id" : " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e " ,
"path" : " /srv/data/uploads/report-2026-q1.csv " ,
"timestamp" : " 2026-02-11T15:32:18Z " ,
"watcher_id" : " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e " ,
"path" : " /srv/data/uploads/quarterly-final.csv " ,
"timestamp" : " 2026-02-11T15:33:02Z " ,
"old_path" : " /srv/data/uploads/report-2026-q1.csv " ,
"oldest_available_id" : 1024 ,
"newest_available_id" : 1271 ,
"oldest_available_timestamp" : " 2026-02-11T15:32:18Z " ,
"newest_available_timestamp" : " 2026-02-11T15:40:11Z "
"code" : " INVALID_PAGINATION " ,
"message" : " Limit must be between 1 and 200 "
Error Code Title Description Resolution INVALID_REQUESTInvalid request Request payload failed validation Check request fields and retry INVALID_PAGINATIONInvalid pagination Page or limit is out of range Use page ≥ 1 and limit between 1 and 200
"code" : " WATCHER_NOT_FOUND " ,
"message" : " Watcher not found "
Error Code Title Description Resolution WATCHER_NOT_FOUNDWatcher not found No watcher exists for provided id List watchers and use a valid watcher id
"message" : " Requested since_id is older than available replay history "
Error Code Title Description Resolution LIMIT_EXCEEDEDResource limit exceeded Watcher or path limits exceeded Reduce paths or delete unused watchers HISTORY_GAPReplay history gap Requested since_id is older than retained replay history Reconnect without since_id or increase history_memory_limit_bytes
Establishes a Server-Sent Events stream that delivers watcher events in real time. Supports replay from a cursor to recover missed events.
Name In Type Required Description idpath string Yes Watcher id since_idquery integer No Replay events strictly after this event id. since_timestampquery string No Replay events strictly after this timestamp. Accepted formats: RFC3339 (e.g. 2026-02-11T15:30:00Z), Unix seconds (e.g. 1739287800), Unix milliseconds (e.g. 1739287800123).
curl -N " https://api.example.com/watchers/9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e/events/sse?since_id=1000 "
const stream = await client . watch . streams . streamSse ( {
id: " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e " ,
for await ( const event of stream) {
console . log (event . kind , event . path );
SSE stream established. Events are delivered as text/event-stream frames. Each frame contains a data line with a JSON-encoded file event:
data: {"id":1024,"watcher_id":"9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e","kind":"modified","path":"/srv/data/uploads/report.csv","timestamp":"2026-02-11T15:32:18Z","is_dir":false,"old_size_bytes":4096,"new_size_bytes":8192}
"code" : " WATCHER_NOT_FOUND " ,
"message" : " Watcher not found "
Error Code Title Description Resolution WATCHER_NOT_FOUNDWatcher not found No watcher exists for provided id List watchers and use a valid watcher id
"message" : " Requested since_id is older than available replay history "
Error Code Title Description Resolution LIMIT_EXCEEDEDResource limit exceeded Watcher or path limits exceeded Reduce paths or delete unused watchers HISTORY_GAPReplay history gap Requested since_id is older than retained replay history Reconnect without since_id or increase history_memory_limit_bytes
"code" : " MAX_CLIENTS_REACHED " ,
"message" : " Watcher has reached max stream clients "
Error Code Title Description Resolution MAX_CLIENTS_REACHEDToo many clients Watcher stream client limit reached Disconnect idle clients or increase max_clients_per_watcher
Upgrades the connection to a WebSocket and streams file events as text frames. Supports replay from a cursor.
Name In Type Required Description idpath string Yes Watcher id since_idquery integer No Replay events strictly after this event id. since_timestampquery string No Replay events strictly after this timestamp. Accepted formats: RFC3339 (e.g. 2026-02-11T15:30:00Z), Unix seconds (e.g. 1739287800), Unix milliseconds (e.g. 1739287800123).
curl -i -N -H " Connection: Upgrade " -H " Upgrade: websocket " \
" https://api.example.com/watchers/9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e/events/ws?since_id=1000 "
const socket = await client . watch . streams . streamWs ( {
id: " 9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e " ,
socket . on ( " message " , ( frame ) => {
const event = JSON . parse (frame . toString ());
console . log (event . kind , event . path );
WebSocket connection upgraded. Subsequent frames contain JSON-encoded file events:
{"id":1024,"watcher_id":"9b2e7a10-1f4d-4b8a-9c1e-2a0f8c3b4d5e","kind":"modified","path":"/srv/data/uploads/report.csv","timestamp":"2026-02-11T15:32:18Z","is_dir":false,"old_size_bytes":4096,"new_size_bytes":8192}
"code" : " WATCHER_NOT_FOUND " ,
"message" : " Watcher not found "
Error Code Title Description Resolution WATCHER_NOT_FOUNDWatcher not found No watcher exists for provided id List watchers and use a valid watcher id
"message" : " Requested since_id is older than available replay history "
Error Code Title Description Resolution LIMIT_EXCEEDEDResource limit exceeded Watcher or path limits exceeded Reduce paths or delete unused watchers HISTORY_GAPReplay history gap Requested since_id is older than retained replay history Reconnect without since_id or increase history_memory_limit_bytes
"code" : " MAX_CLIENTS_REACHED " ,
"message" : " Watcher has reached max stream clients "
Error Code Title Description Resolution MAX_CLIENTS_REACHEDToo many clients Watcher stream client limit reached Disconnect idle clients or increase max_clients_per_watcher
Note
Reconnect with since_id to replay events after the last seen id. If the requested cursor is older than the retained history buffer, the server returns HISTORY_GAP. In that case, reconnect without a cursor or increase history_memory_limit_bytes.