InterviewSolution
Saved Bookmarks
| 1. |
Explain Event driven applications , how is it different from callback function, module used and classes used with examples? |
Answer»
Every action on a computer is an event. Example: File OPENING is an event. Objects in Node.js can fire events like createReadStream object FIRES when opening or closing a file. Example: to read a stream of characters in existing file trnk.txt var fs = require("fs"); var rdstream = fs.createReadStream('trnk.txt'); rdstream.on('open', function(){ console.log("File OPENED"); });Executing above code you will get result as File Opened You can create, fire and listen to your events using Events module, eventEmitter class. Events module and eventEmitter class is used to bind events and event-listener. |
|