os: add os.devNull

Provides the platform-specific file path of the null device.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Luigi Pinca 2021-05-06 15:45:04 +02:00 committed by Danielle Adams
parent 74205b3542
commit e1195312b9
No known key found for this signature in database
GPG Key ID: D3A89613643B6201
3 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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'
}
});

View File

@ -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');
}