Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -259,3 +259,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');
}
Comment on lines +263 to +268
Copy link
Contributor

@bl-ue bl-ue May 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to store os.devNull in a separate variable? I'm not getting it.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency with

const EOL = os.EOL;
if (common.isWindows) {
assert.strictEqual(EOL, '\r\n');
} else {
assert.strictEqual(EOL, '\n');
}