Open In App

Node.js readStream.setRawMode() Method

Last Updated : 11 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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




// Node.js program to demonstrate the
// readStream.setRawMode() method
 
// Importing dgram module
const dgram = require('dgram');
 
 
// Creating and initializing client
// and server socket
const client = dgram.createSocket("udp4");
const server = dgram.createSocket("udp4");
 
// Catching the message event
server.on("message", function (msg) {
 
    // Creating and initializing a
    // ReadStream object
    let ReadStream = process.stdin;
 
    // Setting the read stream Raw mode
    // by using setRawMode() method
    ReadStream.setRawMode(false);
 
    // 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.setRawMode() method
 
// 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");


 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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads