Module:-
The module is used to contain the set of functions to implement functionality that can be called under node js main file.
exports.functionname= function(){
return statements;
}
How to call module under node js main file.
var http = require('http');
var ref = require('./modulename');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write("hello" + ref.methodame());
res.end();
}).listen(8080);
console.log("Program started at localhost 8080");
Now I am explaining the example of SiCalc.js:-
exports.sicalc=function()
{
p=12000;
r=2.2;
t=2;
si = (p*r*t)/100
return si;
}
Code of module:-
var http = require('http');
var ref = require('./simodule');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write("result is " + ref.sicalc());
res.end();
}).listen(8080);
console.log("Program started at localhost 8080");
ASSIGNMENT OF NODE JS,
CREATE this program using the module:-
WAP to create a mark sheet using five different subjects with the following conditions?
1) all subject marks should be 0 to 100?
2) If only one subject mark is <33 then the student will supply.
3) If all subject marks are>33 then the student pass and displays division with percentage?
4) if the minimum of two subject marks is <33 then the student will fail.
5) if the student is suppl and the mark is >28 then five bonus marks will be added then the student will pass by grace and grace subject name.
6) display distinction subject name
7) display suppl subject name
POST Answer of Questions and ASK to Doubt