Skip to content

Commit 4a6f9f2

Browse files
authored
add: Module System(core module, local module, third party module) (#5)
1 parent 4347aaf commit 4a6f9f2

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

3. Module System/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Core Module
2+
const fs = require("fs");
3+
// Local Module
4+
// const localModule = require("./localModule");
5+
const { printName, PI, student, Human } = require("./localModule");
6+
// Third Party Module / on node_modules
7+
// const moment = require("moment");
8+
9+
// console.log(fs);
10+
// console.log(localModule.printName("Drian"), localModule.PI);
11+
console.log(student.printStudent(), new Human());
12+
// console.log(printName("Drian"), PI);
13+
// console.log(moment);

3. Module System/localModule.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const printName = (name) => `Hi, ${name}`;
2+
3+
const PI = 3.14;
4+
5+
const student = {
6+
name: "Drian",
7+
age: 18,
8+
// printStudent: function () {},
9+
// printStudent: () => {},
10+
printStudent() {
11+
return `Hi, my name is ${this.name} and iam ${this.age} years old`;
12+
},
13+
};
14+
15+
class Human {
16+
constructor() {
17+
console.log("Object human created");
18+
}
19+
}
20+
21+
// module.exports.printName = printName;
22+
// module.exports.PI = PI;
23+
24+
// module.exports = {
25+
// printName: printName,
26+
// PI: PI,
27+
// student: student,
28+
// Human: Human,
29+
// };
30+
31+
module.exports = { printName, PI, student, Human };

0 commit comments

Comments
 (0)