Skip to content

Instantly share code, notes, and snippets.

@minons1
Created August 20, 2024 07:06
Show Gist options
  • Save minons1/fe8cd5f45541c0dbdfa00a74555c8980 to your computer and use it in GitHub Desktop.
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`
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