-
Notifications
You must be signed in to change notification settings - Fork 5
Creating custom modules
Nishant Mendiratta edited this page Mar 16, 2014
·
1 revision
function hello(){
return "world";
}
function helloAgain(){
return hello() + " again";
}
function myPrivateFunction(number){
return number + 1;
}
function increment(number){
return myPrivateFunction(number);
}
//Explicitly declaring objects to be used publicly
module.exports.helloworld = hello;
module.exports.helloworldagain = helloAgain;
module.exports.privatefunctionincrement = increment;
/Accessing function/
var myModule = require("./my_module.js");
console.log("First module message : " + myModule.helloworld());
console.log("Second module message : " + myModule.helloworldagain());
console.log("Third module message : " + myModule.privatefunctionincrement(1));
var git_module = require("./github_module.js");
git_module.github("nishantmendiratta",function(repos){
console.log("Nishant Mendiratta repos",repos);
});