Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fs.promises.exists

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs.promises.exists

The missing fs.promises.exists()

  • 1.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

fs.promises.exists Latest version Monthly downloads Install size

The missing fs.promises.exists(). Also supports case-sensitive/insensitive file paths.

If you like this project, please star it & follow me to see what other cool projects I'm working on! ❤️

🙋‍♂️ Why?

  • The fs Promises API doesn't have an exists() method that replaces existsSync().

  • Depending on how the file-system is configured, file paths can be case-sensitive or insensitive. This module lets you specify case regardless of the file-system configuration.

🚀 Install

npm i fs.promises.exists

👨🏻‍🏫 Examples

Basic check

import fsExists from 'fs.promises.exists'

await fsExists('./file-that-exists')
// => true

await fsExists('./file-that-doesnt-exist')
// => false

Case sensitive file path

import fsExists from 'fs.promises.exists'

await fsExists('./CASE-SENSITIVE-FILE-PATH', true)
// => true

await fsExists('./case-sensitive-file-path', true)
// => false

Case insensitive file path

import fsExists from 'fs.promises.exists'

await fsExists('./CASE-SENSITIVE-FILE-PATH', false)
// => ./CASE-SENSITIVE-FILE-PATH ← Retruns truthy case-preserved match

await fsExists('./case-sensitive-file-path', false)
// => ./CASE-SENSITIVE-FILE-PATH ← Retruns truthy case-preserved match

⚙️ API

fsExists(filePath, caseSensitive)

Returns: boolean | string

filePath

Type: string

Required

Path to the file to check the existence of.

caseSensitive

Type: boolean

Optional

Whether to check the existence of the path case-sensitively or not.

  • true - Enforce case sensitive path checking.

  • false - Enforce case insensitive path checking. On match, it returns the case senstive path as a string.

  • undefined - Default behavior is based on the disk formatting of the environment. Specifically, this is the HFS+ file system personality.

    Most default setups (such as macOS) defaults to being case insensitive. That means checking whether ./does-file-exist and ./DoEs-FiLe-ExIsT are equivalent.

Keywords

FAQs

Package last updated on 26 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc