Skip to content

Instantly share code, notes, and snippets.

@macbre
Created January 23, 2023 13:32
Show Gist options
  • Save macbre/cb792cc98ced7207ac71c1c5c5656c96 to your computer and use it in GitHub Desktop.
Save macbre/cb792cc98ced7207ac71c1c5c5656c96 to your computer and use it in GitHub Desktop.
Async fs.exists()
import { fsExists } from './utils';
if ( ! ( await fsExists( folder ) ) ) {
// ...
}
import fsa from 'fs/promises';
// Node.js does not provide a promisified version of fs.exists() (and the latter one is deprecated)
export async function fsExists( path: string ): Promise< boolean > {
return !! ( await fsa.stat( path ).catch( _e => false ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment