This simple example demonstrates the use of the event emitter interface in Node.js. The emitter.js file uses the emitter to emit a random number designated as stock-price every few seconds. This is then intercepted in the app.js file using the .on() event listener and rendered on the console. This way, the event emitter interface enables facilitates a messaging system between modules in Node.js and is used extensively within the asynchronous side of Node.
INSTRUCTIONS
- Type
node app.js
to kick start the application. - You'll see a random stock price amount display every 3 seconds on the console.
Sachin Bhatnagar | sachin@knowledgehut.co