Skip to content

Commit

Permalink
os: remove trailing slash from os.tmpdir()
Browse files Browse the repository at this point in the history
This commit makes `os.tmpdir()` behave consistently on all platforms. It
changes `os.tmpdir()` to always return a path without trailing slash.

Semver: major
Fixes: #715
PR-URL: #747
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
tellnes authored and chrisdickinson committed Apr 28, 2015
1 parent 1bcdf46 commit b57cc51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ exports.platform = function() {
};

exports.tmpdir = function() {
var path;
if (isWindows) {
return process.env.TEMP ||
path = process.env.TEMP ||
process.env.TMP ||
(process.env.SystemRoot || process.env.windir) + '\\temp';
} else {
return process.env.TMPDIR ||
path = process.env.TMPDIR ||
process.env.TMP ||
process.env.TEMP ||
'/tmp';
}
if (/[\\\/]$/.test(path))
path = path.slice(0, -1);
return path;
};

exports.tmpDir = exports.tmpdir;
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if (process.platform === 'win32') {
process.env.TMP = '';
var expected = (process.env.SystemRoot || process.env.windir) + '\\temp';
assert.equal(os.tmpdir(), expected);
process.env.TEMP = '\\temp\\';

This comment was marked as off-topic.

Copy link
@0thorderlogic

0thorderlogic Feb 9, 2021

Guys idk why mine isn't working i am super pissed help pls help!!!!!
Microsoft Windows [Version 10.0.19042.631]
(c) 2020 Microsoft Corporation. All rights reserved.

C:\Users\Aryan Singh\Bigthread>npx create-react-app Bigthread

C:\Users\Aryan Singh\Bigthread>npx create-react-app Bigthread
npm ERR! code ENOLOCAL
npm ERR! Could not install from "Singh\AppData\Roaming\npm-cache_npx\5408" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Aryan Singh\AppData\Roaming\npm-cache_logs\2021-02-09T11_30_38_817Z-debug.log
Install for [ 'create-react-app@latest' ] failed with code 1

C:\Users\Aryan Singh\Bigthread>npx create-react-app Bigthread
npm ERR! code ENOLOCAL
npm ERR! Could not install from "Singh\AppData\Roaming\npm-cache_npx\21184" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Aryan Singh\AppData\Roaming\npm-cache_logs\2021-02-09T11_34_27_462Z-debug.log
Install for [ 'create-react-app@latest' ] failed with code 1

assert.equal(os.tmpdir(), '\\temp');
} else {
assert.equal(os.tmpdir(), '/tmpdir');
process.env.TMPDIR = '';
Expand All @@ -21,6 +23,8 @@ if (process.platform === 'win32') {
assert.equal(os.tmpdir(), '/temp');
process.env.TEMP = '';
assert.equal(os.tmpdir(), '/tmp');
process.env.TMPDIR = '/tmpdir/';
assert.equal(os.tmpdir(), '/tmpdir');
}

var endianness = os.endianness();
Expand Down

0 comments on commit b57cc51

Please sign in to comment.