Created
August 20, 2024 07:06
-
-
Save minons1/fe8cd5f45541c0dbdfa00a74555c8980 to your computer and use it in GitHub Desktop.
How to handle `Error: ENOENT: no such file or directory` when using`createWriteStream`
This file contains hidden or 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 { createWriteStream } from 'fs' | |
(() => { | |
try { | |
const res = createWriteStream('/path/to/not/exists/dir/file.txt') | |
res.on('error', (err) => { | |
console.error('here is how you handle error') | |
}) | |
} catch (error) { | |
console.error('error will not handled here') | |
} | |
console.log('done') | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment