Slip 3
Create a Node.js Application that uses user defined module circle.js which exports the functions area () and circumference () and display the details on console.
// circle.js
exports.area = function (r) {
return PI * r * r;
};
exports.circumference = function (r) {
return 2 * PI * r;
};
//areacircle.js
var circle = require('./circle.js');
console.log( 'The area of a circle of radius 3 is ' + circle.area(3));
console.log( 'The circumference of a circle of radius 3 is '
+ circle.circumference(3));
/* Output*/
C:\Users\NEW\nodex>node areacircle.js
The area of a circle of radius 3 is 28.274333882308138
The circumference of a circle of radius 3 is 18.84955592153876
No comments:
Post a Comment