pages

Saturday, May 29, 2021

Node js Slip no.3



Software solutions

 SYBBA(CA) Practical Slips Solutions

Node JS

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

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);


Initiate mycircle.js file :

C:\Users\Your Name>node mycircle.js



All software solutions

Node Js Slip no.2

SYBBA(CA) Practical Slips Solutions

Node JS

Slip No.2.Create a Node.js Application that uses user defined module to return the factorial of given number.

fact.js

var fact={  

  factorial: function(n)

{

    var f=1,i;

  for(i=1;i<=n;i++)

   {     f=f*i;

   }

  console.log('factorial of '+n+' is:'+f);}};

 module.exports=fact


app.js

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

mymod.factorial(5);


Initiate app.js file :

C:\Users\Your Name>node app.js


Wednesday, May 19, 2021

Node js slip no 1

 SYBBA(CA) Sem IV  Node Js slips solutions

 Slip No 1

Q1. Create a Node.js file that will convert the output "Hello World!" into upper-case letters.


var http = require('http');

var uc = require('upper-case');

http.createServer(function (req, res) {

  res.writeHead(200, {'Content-Type': 'text/html'});

  res.write(uc.upperCase("Hello World!"));

  res.end();

}).listen(8080);


Save the code above in a file called "d_uppercase.js", and initiate the file:

First Install module 'upper-case' using npm

C:\Users\Your Name>npm install upper-case

Initiate d_uppercase:

C:\Users\Your Name>node d_uppercase.js

If you have followed the same steps on your computer, you will see the same result as the example: http://localhost:8080