Skip to content

Commit

Permalink
doc: clarify fs.mkdtemp prefix argument
Browse files Browse the repository at this point in the history
Per: #6142

Clarify the prefix argument.

Fixes: #6142
PR-URL: #6800
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
  • Loading branch information
jasnell committed May 18, 2016
1 parent 56ae651 commit 2ccba1f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,37 @@ fs.mkdtemp('/tmp/foo-', (err, folder) => {
});
```

*Note*: The `fs.mkdtemp()` method will append the six randomly selected
characters directly to the `prefix` string. For instance, given a directory
`/tmp`, if the intention is to create a temporary directory *within* `/tmp`,
the `prefix` *must* end with a trailing platform-specific path separator
(`require('path').sep`).

```js
// The parent directory for the new temporary directory
const tmpDir = '/tmp';

// This method is *INCORRECT*:
fs.mkdtemp(tmpDir, (err, folder) => {
if (err) throw err;
console.log(folder);
// Will print something similar to `/tmp-abc123`.

This comment has been minimized.

Copy link
@thefourtheye

thefourtheye May 18, 2016

Contributor

Ah, I wanted to check this when I get in front of a computer before approving. #6834

// Note that a new temporary directory is created
// at the file system root rather than *within*
// the /tmp directory.
});

// This method is *CORRECT*:
const path = require('path');
fs.mkdtemp(tmpDir + path.sep, (err, folder) => {
if (err) throw err;
console.log(folder);
// Will print something similar to `/tmp/abc123`.
// A new temporary directory is created within
// the /tmp directory.
});
```

## fs.mkdtempSync(template)
<!-- YAML
added: v5.10.0
Expand Down

0 comments on commit 2ccba1f

Please sign in to comment.