Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
path-exists
Advanced tools
The path-exists npm package is used to check if a file or directory exists on the file system without using fs.existsSync. It is built on top of Node.js's fs.promises API and provides a simple promise-based interface.
Check if a path exists
This feature allows you to check if a file or directory exists asynchronously by returning a promise that resolves to either true or false.
const pathExists = require('path-exists');
(async () => {
const exists = await pathExists('/path/to/file');
console.log(exists);
//=> true or false
})();
Check if a path exists synchronously
This feature provides a synchronous way to check if a file or directory exists, returning a boolean value immediately.
const pathExists = require('path-exists');
const exists = pathExists.sync('/path/to/file');
console.log(exists);
//=> true or false
fs-extra is a package that extends the built-in fs module, providing additional methods and ensuring consistency across platforms. It includes the 'pathExists' and 'pathExistsSync' methods, which are similar to the functionality provided by path-exists. fs-extra offers a broader set of file system operations, making it a more comprehensive choice for file system interactions.
make-dir is a package that focuses on creating directories and their parent directories if they don't exist. While it doesn't provide a direct method to check for the existence of a path, it is related in the sense that it handles the existence of directories as part of its operation. It differs from path-exists as it is more about directory creation than existence checking.
Check if a path exists
NOTE: fs.existsSync
has been un-deprecated in Node.js since 6.8.0. If you only need to check synchronously, this module is not needed.
Never use this before handling a file though:
In particular, checking if a file exists before opening it is an anti-pattern that leaves you vulnerable to race conditions: another process may remove the file between the calls to
fs.exists()
andfs.open()
. Just open the file and handle the error when it's not there.
$ npm install path-exists
// foo.js
import {pathExists} from 'path-exists';
console.log(await pathExists('foo.js'));
//=> true
Returns a Promise<boolean>
of whether the path exists.
Returns a boolean
of whether the path exists.
FAQs
Check if a path exists
We found that path-exists demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.