Slip 3 - A) Create a Node.js Application that uses user defined module circlejs which exports the functions area () and circumference () and display the details on console.

 Solution:

circle.js


var circle={  

  area: function(r)

{

    var pi=3.14,a;  

     a=pi*r*r;

  

  console.log('area of circle is:'+a);

},

circumference: function(r)

{

    var pi=3.14,c;

  c=2*pi*r;

  console.log('circumference of circle is:'+c);

}

};

 module.exports=circle



mycircle.js


var mymod=require('C:/Users/Public/node_prog/circle.js');

mymod.area(5);

mymod.circumference(5);

Post a Comment

1 Comments