From ee7a26153f6d8da717d357e0ce4b16f6c89a2156 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Thu, 14 Sep 2017 14:26:42 +0200 Subject: [PATCH 1/2] doc: make mkdtemp example work on Windows Fixes: https://github.com/nodejs/node/issues/14960 --- doc/api/fs.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 0ae7fee6cb5afc..44cd4471516c1a 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -1536,10 +1536,11 @@ object with an `encoding` property specifying the character encoding to use. Example: ```js -fs.mkdtemp('/tmp/foo-', (err, folder) => { +const tempFolder = process.platform === 'win32' ? process.env['TEMP'] : '/tmp'; +fs.mkdtemp(path.join(tempFolder, 'foo-'), (err, folder) => { if (err) throw err; console.log(folder); - // Prints: /tmp/foo-itXde2 + // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2 }); ``` From 48ed7d0ff9d852cea98c627352df832180b8b462 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Thu, 14 Sep 2017 16:35:22 +0200 Subject: [PATCH 2/2] fixup: use os.tmpdir() --- doc/api/fs.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 44cd4471516c1a..a44bbd368eef44 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -1536,8 +1536,7 @@ object with an `encoding` property specifying the character encoding to use. Example: ```js -const tempFolder = process.platform === 'win32' ? process.env['TEMP'] : '/tmp'; -fs.mkdtemp(path.join(tempFolder, 'foo-'), (err, folder) => { +fs.mkdtemp(path.join(os.tmpdir(), 'foo-'), (err, folder) => { if (err) throw err; console.log(folder); // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2 @@ -1552,7 +1551,7 @@ the `prefix` *must* end with a trailing platform-specific path separator ```js // The parent directory for the new temporary directory -const tmpDir = '/tmp'; +const tmpDir = os.tmpdir(); // This method is *INCORRECT*: fs.mkdtemp(tmpDir, (err, folder) => {