joyent/node — Issue #2270: "EEXIST, file already exists" when such file does NOT exist
Author: gabipetrovay
Created: 2011-12-04 20:20:13+00:00
State: open

Hi,

Working with the fs module I get the following error:
```Error: EEXIST, file already exists '/home/gabriel/tmp/myDir'```

```
var destDir = '/home/gabriel/tmp/myDir';
if (!path.existsSync(destDir)) {
fs.mkdirSync(destDir);
}
// do some file stream operations and close the streams
```

The error is thrown by ```fs.mkdirSync```. How is this possible? path.existsSync returns false which means the directory does NOT exist. That is also what I am actually doing:
1. I run the code once and destDir gets created
2. I run the code a second time and stop before the if expression is evaluated.
3. I delete destDir and continue execution
4. The if is now entered and the error is thrown by the fs.mkdirSync call.

I tried to replicate it in a small example but there is works. I don't understand why this happens.

Context: these fs operations are in a request route handler. So the same nodejs process execution.

Gabriel