Created
January 23, 2023 13:32
-
-
Save macbre/cb792cc98ced7207ac71c1c5c5656c96 to your computer and use it in GitHub Desktop.
Async fs.exists()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { fsExists } from './utils'; | |
if ( ! ( await fsExists( folder ) ) ) { | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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