I'm trying to make a module with an even that I could call from the index file (after a require).
My code includes var events = require("events");
and I've wrote only the tricky part here.
index.js:
var reqw = require('./module.js');
reqw.on('data', function(d) {
console.log(d);
});
module.js:
module.exports = {
listaccts: function() {
events.EventEmitter.call(this);
}
}
util.inherits(exports.listaccts, events.EventEmitter);
exports.listaccts.prototype.listme = function() {
thisList = this;
var req = https.request(requestOptions, function(res) {
res.on('data', function(chuck) {
store = chuck;
});
res.on('end', function(d) {
thisList.emit("data", store.toString());
});
});
}
Searched the whole we and yet to find a proper answer..