Skip to content

Commit

Permalink
os: add os.devnull()
Browse files Browse the repository at this point in the history
Returns the platform-specific file path of the null device.
  • Loading branch information
lpinca committed May 8, 2021
1 parent aed17e9 commit 74d0f9a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/api/os.md
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
-->

* Returns: {string}

Returns 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
9 changes: 9 additions & 0 deletions lib/os.js
Expand Up @@ -349,9 +349,18 @@ function userInfo(options) {
return user;
}

/**
* @returns {'\\.\nul' | '/dev/nul'}
*/
function devnull() {
return isWindows ? '\\\\.\\nul' : '/dev/null';
}
devnull[SymbolToPrimitive] = devnull;

module.exports = {
arch,
cpus,
devnull,
endianness,
freemem: getFreeMem,
getPriority,
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-os.js
Expand Up @@ -259,3 +259,13 @@ 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');
}

assert.strictEqual(`${os.devnull}`, devnull);

0 comments on commit 74d0f9a

Please sign in to comment.