Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing fs.existsSync #128

Open
Pomax opened this issue Oct 11, 2024 · 4 comments
Open

Missing fs.existsSync #128

Pomax opened this issue Oct 11, 2024 · 4 comments

Comments

@Pomax
Copy link

Pomax commented Oct 11, 2024

It looks like the fairly critical fs.existsSync is missing from the set of available functions, which makes otherwise "simple if check" code a "try/catch with dangling let variables" mess. Could .existsSync be added?

@jcubic
Copy link
Contributor

jcubic commented Oct 11, 2024

fs.exists is deprecated in Node.js, so I don't see a reason for adding this.

@jcubic
Copy link
Contributor

jcubic commented Oct 11, 2024

You can create this function very easy if you need it:

async function exists(path) {
  try {
    await fs.stat(path);
    return true;
  } catch(e) {
    return false;
  }
}

or

function exists(path) {
  return fs.stat(path)
    .then(() => true)
    .catch(() => false);
}

no need for dangling let.

@Pomax
Copy link
Author

Pomax commented Oct 11, 2024

Sure, but existsSync is not (not sure why I wrote exists without that, all my code uses the sync version... updated the title and initial comment).

I know it's easy enough to shim, but that shouldn't be necessary.

@Pomax Pomax changed the title Missing fs.exists Missing fs.existsSync Oct 11, 2024
@jcubic
Copy link
Contributor

jcubic commented Oct 11, 2024

I don't think that you can implement existsSync with lightingFS that use promise based API.

But if you want to contribute and implement it (even that I think it's not possible) go ahead.

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

No branches or pull requests

2 participants