ProvenPin Install

chokidar watch temp directory add events: working versions (tested 2026-10-15)

Watch a temporary directory with chokidar and assert add events when files are written, all offline.

passed1 passed · 0 failed2026-10-15 20:56 UTC
Status
passed
Last passed
2026-10-15 20:56 UTC
Tests
1 / 1
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
chokidar@5.0.0@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38805962781

The code

Exactly the files that passed. Your agent can pull them with get_recipe("chokidar-temp-watch") (install), or see them on GitHub.

package.json
{
  "name": "chokidar-temp-watch",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "chokidar": "5.0.0"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/watch.ts
import chokidar from "chokidar";

export function watchDir(dir: string, onAdd: (path: string) => void) {
  const watcher = chokidar.watch(dir, {
    ignoreInitial: true,
    awaitWriteFinish: { stabilityThreshold: 50, pollInterval: 20 },
  });
  watcher.on("add", onAdd);
  return watcher;
}
test/watch.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { setTimeout as sleep } from "node:timers/promises";
import { watchDir } from "../src/watch.ts";

test("emits add when a file appears", async () => {
  const dir = mkdtempSync(join(tmpdir(), "chok-"));
  const seen: string[] = [];
  const watcher = watchDir(dir, (p) => seen.push(p));
  try {
    await sleep(100);
    writeFileSync(join(dir, "hello.txt"), "hi");
    const deadline = Date.now() + 3000;
    while (seen.length === 0 && Date.now() < deadline) await sleep(50);
    assert.ok(seen.some((p) => p.endsWith("hello.txt")));
  } finally {
    await watcher.close();
    rmSync(dir, { recursive: true, force: true });
  }
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.