UNPKG

nodejs-dac-examples

Version:

42 lines (37 loc) 1.18 kB
//Nodejs gives a module.exports API to create a code and export it as a module. /*******************Using Anonymous Module*************** module.exports = (function(){ var cart = []; function add(item){ cart.push(item); } function getAll(){ return cart; } //functions created in the module are private..... //return gets an object that has methods called addToCart which points to the add Func and displayAll would point to getAll Func in the module. return { addToCart : add, displayAll : getAll } })(); ******************Using named Modules******************/ module.exports.cartApp = (function(){ var cart = []; function add(item){ cart.push(item); } function getAll(){ return cart; } //functions created in the module are private..... //return gets an object that has methods called addToCart which points to the add Func and displayAll would point to getAll Func in the module. return { addToCart : add, displayAll : getAll } })(); exports.title ="Training in Java"; exports.date = new Date();//creating data in javascript exports. developedBy ="Phaniraj B.N." //module.exports = exports.