Get your own Node server
// process.stdin is a ReadStream

console.log('Enter some text (press Ctrl+D or Ctrl+C to end input):');

// Set the encoding to utf8 to get strings instead of Buffer objects
process.stdin.setEncoding('utf8');

let inputData = '';

// Handle data from stdin
process.stdin.on('data', (chunk) => {
  console.log(`Received chunk: "${chunk.trim()}"`);
  inputData += chunk;
});

// Handle the end of input
process.stdin.on('end', () => {
  console.log('\nEnd of input.');
  console.log(`Total input received: ${inputData.length} characters`);
  console.log('You entered:');
  console.log('-'.repeat(20));
  console.log(inputData);
  console.log('-'.repeat(20));
});

// Handle Ctrl+C (SIGINT)
process.on('SIGINT', () => {
  console.log('\nInput interrupted with Ctrl+C');
  process.exit();
});

              
Enter some text (press Ctrl+D or Ctrl+Z to end input):
> Hello, this is a test
Received chunk: "Hello, this is a test"
> This is another line
Received chunk: "This is another line"

End of input.
Total input received: 38 characters
You entered:
--------------------
Hello, this is a test
This is another line
--------------------