Skip to content

Commit

Permalink
os: add os.devNull
Browse files Browse the repository at this point in the history
Provides the platform-specific file path of the null device.

PR-URL: #38569
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
lpinca authored and BethGriggs committed Aug 12, 2021
1 parent 6616853 commit 84feb3b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/api/os.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ The properties included on each object include:
`nice` values are POSIX-only. On Windows, the `nice` values of all processors
are always 0.

## `os.devNull`
<!-- YAML
added: REPLACEME
-->

* {string}

The platform-specific file path of the null device.

* `\\.\nul` on Windows
* `/dev/null` on POSIX

## `os.endianness()`
<!-- YAML
added: v0.9.4
Expand Down
7 changes: 7 additions & 0 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,5 +382,12 @@ ObjectDefineProperties(module.exports, {
enumerable: true,
writable: false,
value: isWindows ? '\r\n' : '\n'
},

devNull: {
configurable: true,
enumerable: true,
writable: false,
value: isWindows ? '\\\\.\\nul' : '/dev/null'
}
});
7 changes: 7 additions & 0 deletions test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,10 @@ if (!common.isIBMi) {

is.number(+os.freemem, 'freemem');
is.number(os.freemem(), 'freemem');

const devNull = os.devNull;
if (common.isWindows) {
assert.strictEqual(devNull, '\\\\.\\nul');
} else {
assert.strictEqual(devNull, '/dev/null');
}

0 comments on commit 84feb3b

Please sign in to comment.