Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: add os.devNull #38569

Closed
wants to merge 1 commit into from
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');
}