Skip to content

Instantly share code, notes, and snippets.

@Unitecho
Created January 30, 2013 05:18
Show Gist options
  • Save Unitecho/4670842 to your computer and use it in GitHub Desktop.
Save Unitecho/4670842 to your computer and use it in GitHub Desktop.
Node : Module creation without arguments
var EventEmitter = require('events').EventEmitter;
module.exports = new EventEmitter();
setTimeout(function() {
module.exports.emit('ready');
}, 1000);
exports.toto = function() {
console.log('Toto called');
}
function longfunction() {
console.log('Long function called');
}
//module.exports.tata = longfunction;
// SAME as
exports.tata = longfunction;
//module.exports = {
// add : function(a, b) {return a + b},
// sub : function(a, b) {return a - b}
//}
---- index.js :
var exp = require('./exported.js');
console.log(exp);
exp.on('ready', function() {
console.log('module a is ready');
});
// //console.log(exp.add(2, 4));
// //console.log(exp.sub(10, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment