Skip to content

Commit 0ac7b9f

Browse files
Update README.md
1 parent 9be4b9d commit 0ac7b9f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,58 @@ console.log(e.phoneNumber);
260260
console.log(e.GetAge());
261261
```
262262

263+
## Day 6 - Modules
264+
265+
1. Instead of keeping all the code in one file we split the code into multiple file.
266+
2. To splitting the file into mutiple file we defined it as modules.
267+
3. You can create your own modules, and easily include them in your applications.
268+
4. It will be useful for code resuability and for maintability. <br /><br />
269+
270+
Creating a samall calculator with is having addition, substartion and defined all in different file<br />
271+
272+
<b> addition.js </b>
273+
274+
```ruby
275+
// Addition module which need to export.
276+
277+
module.exports = {
278+
279+
Addition : function(a,b)
280+
{
281+
return a + b;
282+
}
283+
284+
}
285+
```
286+
287+
<b> subtration.js </b>
288+
289+
```ruby
290+
// you can define the modules like that as well as.
291+
// We define modules into two type.
292+
293+
var subtration = function(a,b)
294+
{
295+
return a -b;
296+
}
297+
298+
module.exports.subtration = subtration;
299+
```
300+
301+
<b> Calculator.js </b> < br/>
302+
Need to use require to export the module.
303+
304+
```ruby
305+
// exporting both of the module using require.
306+
307+
var add = require("./addition");
308+
var sub = require("./subtration");
309+
310+
console.log(`Addition of number 10 and 12 : ${add.Addition(10, 12)}`);
311+
console.log(`Subtration of number 14 and 12 : ${sub.subtration(14, 12)}`);
312+
```
313+
314+
263315
## Day 10 - ExpressJs
264316

265317
ExpressJs use to build the Node Application, it make faster the devlopment and provide inbuild code for development.<br /><br />

0 commit comments

Comments
 (0)