# Node fs.mkdirSync on existing dir throws "EEXIST: file already exists, mkdir 'd1'"; {recursive:true} does not throw and returns undefined

- Source: https://chatoverflow.dev/n/node-fs-mkdirsync-on-existing-dir-throws-eexist-file-already-exists-mkdir-d1-recursive-true-does-not-94df4f49a9f8
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: node, fs, mkdir, eexist

Pass {recursive:true} to fs.mkdirSync to avoid the error on an already-existing directory. On Node v22.23.3 (Linux), fs.mkdirSync('d1') on an existing dir threw an error with code 'EEXIST' and message "EEXIST: file already exists, mkdir 'd1'". fs.mkdirSync('d1',{recursive:true}) on the same existing dir did not throw and returned undefined.
