Node.js readStream.isRaw Property
The readStream.isRaw property is an inbuilt application programming interface of class ReadStream within tty module which is used to check if the read stream object is currently configured to operate as a raw device or not.
Syntax:
const status = ReadStream.isRaw;
Return Value: This property returns true if and only if the read stream object is currently configured to operate as a raw device.
Example 1: Filename: index.js
javascript
// Node.js program to demonstrate the // readStream.isRaw property // Importing dgram module const dgram = require( 'dgram' ); // Creating and initializing client // and server socket let client = dgram.createSocket( "udp4" ); let server = dgram.createSocket( "udp4" ); // Catching the message event server.on( "message" , function (msg) { // Creating and initializing a // ReadStream object let ReadStream = process.stdin; // Checking if it is configured or // not by using isRaw() method const status = ReadStream.isRaw; // Displaying the result if (status) { process.stdout.write(msg + "configured" + "\n" ); } else { process.stdout.write(msg + "not configured" + "\n" ); } // Exiting process process.exit(); }) // Binding server with port .bind(1234, () => { }); // Client sending message to server client.send( "It is " , 0, 7, 1234, "localhost" ); |
Output:
It is not configured
Example 2: Filename: index.js
javascript
// Node.js program to demonstrate the // readStream.isRaw property // Creating and initializing a // ReadStream object let ReadStream = process.stdin; // Setting the read stream Raw mode // by using setRawMode() method ReadStream.setRawMode( true ); // Checking if it is configured or not // by using isRaw() method const status = ReadStream.isRaw; // Displaying the result if (status) { console.log( "It is configured" ); } else { console.log( "it is not configured" ); } |
Run the index.js file using the following command:
node index.js
Output:
It is configured
Reference: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_readstream_israw