docs: simplify file existence example to use node:fs#3029
Conversation
Rewrite the checking_file_existence example to use the Node.js-compatible `fs.exists` and `fs/promises.access` APIs instead of Deno-specific APIs. Closes #2987 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fibibot
left a comment
There was a problem hiding this comment.
Two issues to address:
-
fs.existsis deprecated upstream — Node's fs docs mark it "Stability: 0 — Deprecated: Use fs.stat() or fs.access() instead." A beginner-tagged example shouldn't lead with a deprecated callback API. The promise-basedaccessblock is the recommended replacement; consider making it the only example. -
The TOCTOU warning was deleted. The original called out "Can create a race condition if followed by file operation" and pointed at the
Deno.lstatpattern as the race-free alternative. The new example removes the warning — and the linked feedback (#2987) is asking to use this forif (!exists(path)) { create() }, which is exactly the racy pattern users need to be steered away from.
lunadogbot
left a comment
There was a problem hiding this comment.
import { exists } from "node:fs"puts a deprecated callback API into a beginner-tagged example. Node marksfs.exists()as deprecated and recommendsfs.stat()orfs.access()instead (https://nodejs.org/api/fs.html#fsexistspath-callback), so this page should keep the promise-basedaccessexample or use direct operation+error handling.- The race-condition warning was removed. The intro still frames this as useful before creating files, but checking existence before a later write is exactly the TOCTOU pattern the old example warned about; keep that warning or rewrite the example so it handles
EEXIST/NotFoundat the operation site.
Summary
node:fsexistsandnode:fs/promisesaccessAPIs@std/fs/existsandDeno.lstatapproaches in favor of the simpler, more familiar Node.js-compatible APIsCloses #2987
Test plan
deno run -R🤖 Generated with Claude Code