Skip to content

docs: simplify file existence example to use node:fs#3029

Open
bartlomieju wants to merge 1 commit into
mainfrom
docs/file-existence-node-fs-2987
Open

docs: simplify file existence example to use node:fs#3029
bartlomieju wants to merge 1 commit into
mainfrom
docs/file-existence-node-fs-2987

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • Rewrites the file existence checking example to use node:fs exists and node:fs/promises access APIs
  • Removes the Deno-specific @std/fs/exists and Deno.lstat approaches in favor of the simpler, more familiar Node.js-compatible APIs

Closes #2987

Test plan

  • Verify the example renders correctly on the docs site
  • Run the example script with deno run -R

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown
Contributor

@fibibot fibibot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues to address:

  1. fs.exists is 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-based access block is the recommended replacement; consider making it the only example.

  2. The TOCTOU warning was deleted. The original called out "Can create a race condition if followed by file operation" and pointed at the Deno.lstat pattern as the race-free alternative. The new example removes the warning — and the linked feedback (#2987) is asking to use this for if (!exists(path)) { create() }, which is exactly the racy pattern users need to be steered away from.

Copy link
Copy Markdown
Contributor

@lunadogbot lunadogbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. import { exists } from "node:fs" puts a deprecated callback API into a beginner-tagged example. Node marks fs.exists() as deprecated and recommends fs.stat() or fs.access() instead (https://nodejs.org/api/fs.html#fsexistspath-callback), so this page should keep the promise-based access example or use direct operation+error handling.
  2. 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/NotFound at the operation site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feedback: /examples/checking_file_existence/ - Needs Improvement

3 participants