Events

// Require in the 'events' core module
let events = require('events');
 
// Create an instance of the EventEmitter class
let emitter = new events.EventEmitter();
emitter.on('ev', () => {
	console.log('when ev is emitted this func will be called');
});


emitter.emit('ev');



// or with args
emitter.on('ev', (data) => {
	console.log('when ev is emitted this func will be called');
});


emitter.emit('ev', 'data');

Take user input

// must be 'data'
process.stdin.on('data', (userInput) => {
  let input = userInput.toString() // note we turn the class returned into a string
  console.log(input)
});

Output

process.stdout.write(data)