Skip to content

Commit e119531

Browse files
lpincadanielleadams
authored andcommitted
os: add os.devNull
Provides the platform-specific file path of the null device. PR-URL: #38569 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent 74205b3 commit e119531

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

doc/api/os.md

+12
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+
* {string}
131+
132+
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

lib/os.js

+7
Original file line numberDiff line numberDiff line change
@@ -382,5 +382,12 @@ ObjectDefineProperties(module.exports, {
382382
enumerable: true,
383383
writable: false,
384384
value: isWindows ? '\r\n' : '\n'
385+
},
386+
387+
devNull: {
388+
configurable: true,
389+
enumerable: true,
390+
writable: false,
391+
value: isWindows ? '\\\\.\\nul' : '/dev/null'
385392
}
386393
});

test/parallel/test-os.js

+7
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,10 @@ if (!common.isIBMi) {
257257

258258
is.number(+os.freemem, 'freemem');
259259
is.number(os.freemem(), 'freemem');
260+
261+
const devNull = os.devNull;
262+
if (common.isWindows) {
263+
assert.strictEqual(devNull, '\\\\.\\nul');
264+
} else {
265+
assert.strictEqual(devNull, '/dev/null');
266+
}

0 commit comments

Comments
 (0)