Skip to content

Commit 7d4759b

Browse files
committed
os: add os.devnull()
Returns the platform-specific file path of the null device.
1 parent ad1961d commit 7d4759b

File tree

6 files changed

+31
-20
lines changed

6 files changed

+31
-20
lines changed

doc/api/os.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ The properties included on each object include:
122122
`nice` values are POSIX-only. On Windows, the `nice` values of all processors
123123
are always 0.
124124

125+
## `os.devnull()`
126+
<!-- YAML
127+
added: REPLACEME
128+
-->
129+
130+
* Returns: {string}
131+
132+
Returns the platform-specific file path of the null device:
133+
134+
* `\\.\nul` on Windows
135+
* `/dev/null` on POSIX
136+
125137
## `os.endianness()`
126138
<!-- YAML
127139
added: v0.9.4

doc/api/path.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,6 @@ process.env.PATH.split(path.delimiter);
135135
// Returns ['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\node\\']
136136
```
137137

138-
## `path.devnull`
139-
<!-- YAML
140-
added: REPLACEME
141-
-->
142-
143-
* {string}
144-
145-
Provides the platform-specific file path of the null device:
146-
147-
* `\\.\nul` on Windows
148-
* `/dev/null` on POSIX
149-
150138
## `path.dirname(path)`
151139
<!-- YAML
152140
added: v0.1.16

lib/os.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,18 @@ function userInfo(options) {
349349
return user;
350350
}
351351

352+
/**
353+
* @returns {string}
354+
*/
355+
function devnull() {
356+
return isWindows ? '\\\\.\\nul' : '/dev/null';
357+
}
358+
devnull[SymbolToPrimitive] = () => devnull();
359+
352360
module.exports = {
353361
arch,
354362
cpus,
363+
devnull,
355364
endianness,
356365
freemem: getFreeMem,
357366
getPriority,

lib/path.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,6 @@ const win32 = {
10651065
return ret;
10661066
},
10671067

1068-
devnull: '\\\\.\\nul',
10691068
sep: '\\',
10701069
delimiter: ';',
10711070
win32: null,
@@ -1532,7 +1531,6 @@ const posix = {
15321531
return ret;
15331532
},
15341533

1535-
devnull: '/dev/null',
15361534
sep: '/',
15371535
delimiter: ':',
15381536
win32: null,

test/parallel/test-os.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,13 @@ if (!common.isIBMi) {
259259

260260
is.number(+os.freemem, 'freemem');
261261
is.number(os.freemem(), 'freemem');
262+
263+
const devnull = os.devnull();
264+
265+
if (common.isWindows) {
266+
assert.strictEqual(devnull, '\\\\.\\nul');
267+
} else {
268+
assert.strictEqual(devnull, '/dev/null');
269+
}
270+
271+
assert.strictEqual(`${os.devnull}`, devnull);

test/parallel/test-path.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ assert.strictEqual(path.win32.delimiter, ';');
6767
// posix
6868
assert.strictEqual(path.posix.delimiter, ':');
6969

70-
// path.devnull tests
71-
// windows
72-
assert.strictEqual(path.win32.devnull, '\\\\.\\nul');
73-
// posix
74-
assert.strictEqual(path.posix.devnull, '/dev/null');
75-
7670
if (common.isWindows)
7771
assert.strictEqual(path, path.win32);
7872
else

0 commit comments

Comments
 (0)