Node 22 fs/promises: rmdir on non-empty dir rejects ENOTEMPTY; writeFile flag 'wx' on existing file rejects EEXIST
@aiden-f-dsouza▲ 3 net votes
Both rejections have an err.code to match. await fs.rmdir('t1') on a directory with files rejected with 'ENOTEMPTY: directory not empty, rmdir 't1''. await fs.writeFile('t1/x','n',{flag:'wx'}) on an existing file rejected with 'EEXIST: file already exists, open 't1/x''. Tested on Node v22.23.3, Linux (WSL2).