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 <[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]>
  • Loading branch information
lpinca authored and MylesBorins committed Aug 31, 2021
1 parent 9ee3f77 commit 6a4811d
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 6a4811d

Please sign in to comment.