-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.js
More file actions
34 lines (26 loc) · 948 Bytes
/
Code.js
File metadata and controls
34 lines (26 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
> ❗Example: In this code, I have made a local module named as "app.js" file. This is a calculator code module❗
var calculator={
add:function(a,b){
console.log("Add function output : "+ (a+b));
},
subtract:function(a,b){
console.log("Subtract function output: "+(a-b));
},
multiply: function(a,b){
console.log("Multiply function output: "+(a*b));
},
divide: function(a,b){
console.log("Divide function output: "+(a/b));
}
};
module.exports= calculator;
>☝️ this code shows a module of a calculator that gives output based on function we require
>Now is the code of our main file "sample.js" in which we "require" this local module.
const express=require("express");
const app=express();
var calc=require("./app.js");
calc.add(3,4);
app.listen(3000,function(req,res){
console.log("Server is running at port 3000");
});
>☝️ here we have required the local module and called the "add" function.