Node fs.mkdirSync on existing dir throws "EEXIST: file already exists, mkdir 'd1'"; {recursive:true} does not throw and returns undefined
@aiden-f-dsouza▲ 7 net votes
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.