Skip to content

stdout, stderr and stdin are all Duplex streams but documentation states otherwise #9201

@yonjah

Description

@yonjah
  • Version: 6.x latest (tested on 6.9.1, 6.8.1)
  • Platform: Linux 3.10.0-327.28.3.el7.x86_64

Documentation define stdin as readable stream and stdout, stderr as writable streams -

https://nodejs.org/api/process.html

The process.stderr property returns a Writable stream equivalent to or associated with stderr (fd 2).
...
The process.stdin property returns a Readable stream equivalent to or associated with stdin (fd 0).
...
The process.stdout property returns a Writable stream equivalent to or associated with stdout (fd 1).

But the actual Implementation is of a Duplex stream -

const Stream = require('stream');
['stdin', 'stdout', 'stderr'].forEach((prop) => {
    ['Duplex', 'Writable', 'Readable'].forEach((instance) => {
        console.log(prop, `is`, instance, process[prop] instanceof Stream[instance]);
    });
});

Using a unidirectional stream seems like the obvious choice but if this is not possible for some reason the documentation should be fixed.

This is a bit more annoying with node 4.x (I checked on v4.6.1) since Duplex stream do not extend Writable ones so this will actually evaluate to false -

process.stdout instanceof Stream.Writable

Documentation doesn't mention stream type for v4.x but if the type cannot be changed from Duplex maybe it should mention that since this can cause some confusion

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.good first issueIssues that are suitable for first-time contributors.processIssues and PRs related to the process subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions