Skip to content

Instantly share code, notes, and snippets.

@shaikh-shahid
Last active April 6, 2016 09:01
Show Gist options
  • Save shaikh-shahid/9f305f6956b3caafa3234741fbc2005c to your computer and use it in GitHub Desktop.
Save shaikh-shahid/9f305f6956b3caafa3234741fbc2005c to your computer and use it in GitHub Desktop.
var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter();
var fs = require('fs');
// Event to read file - generic function.
emitter.on('start_read',function(file_name) {
console.log("Started Reading file....\n\n");
fs.readFile(file_name, 'utf8', function (err,data) {
if (err) {
console.log("Error happens.");
} else {
console.log("File data", data);
}
});
});
// Let's read some file.
emitter.emit('start_read','env.json');
emitter.emit('start_read','envConfig.js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment