Q.1 Create a Node.js Application that uses user defined Module to return the factorial of given number.
//create two files first file name fact.js and second file name Node.js
fact.js
function fact(n){
var f=1;
for(i=1;i<=n;i++)
{
f=f*i;
};
return f;
};
module.exports=fact;
var f=1;
for(i=1;i<=n;i++)
{
f=f*i;
};
return f;
};
module.exports=fact;
Node1.js
var fact=require("./fact.js");
console.log("Factorial of a number : ",fact(5));
Output
C:\Users\NEW\nodex>node Node1.js
Factorial of a number : 120
No comments:
Post a Comment