Node.js readStream.setRawMode() Method
Last Updated :
11 Apr, 2023
The readStream.setRawMode() method is an inbuilt application programming interface of class ReadStream within ‘tty’ module which is used to set the raw mode of the Read stream object to work as a raw device.
Syntax:
const readStream.setRawMode( mode )
Parameters: This method takes the Boolean value as an argument.
Return Value: This method does not return any value.
Example 1: Filename: index.js
Javascript
const dgram = require( 'dgram' );
const client = dgram.createSocket( "udp4" );
const server = dgram.createSocket( "udp4" );
server.on( "message" , function (msg) {
let ReadStream = process.stdin;
ReadStream.setRawMode( false );
const status = ReadStream.isRaw;
if (status)
process.stdout.write(msg + "configured" + "\n" );
else
process.stdout.write(msg + "not configured" + "\n" );
process.exit();
})
.bind(1234, () => {
});
client.send( "It is " , 0, 7, 1234, "localhost" );
|
Output:
It is not configured
Example 2: Filename: index.js
Javascript
let ReadStream = process.stdin;
ReadStream.setRawMode( true );
const status = ReadStream.isRaw;
if (status)
console.log( "It is configured" );
else
console.log( "It is not configured" );
|
Output:
It is configured
Run the index.js file using the following command:
node index.js
Reference: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_readstream_setrawmode_mode
Share your thoughts in the comments
Please Login to comment...