| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 18c3881 commit a858e98
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,24 +6,25 @@ | |||
| 6 | 6 | ||
| 7 | 7 | Node.js has a simple module loading system. In Node.js, files and modules | |
| 8 | 8 | are in one-to-one correspondence (each file is treated as a separate module). | |
| 9 | - As an example, `foo.js` loads the module `circle.js` in the same directory. | ||
| 10 | 9 | ||
| 11 | - The contents of `foo.js`: | ||
| 10 | + As an example, consider a file named `foo.js`: | ||
| 12 | 11 | ||
| 13 | 12 | ```js | |
| 14 | 13 | const circle = require('./circle.js'); | |
| 15 | 14 | console.log(`The area of a circle of radius 4 is ${circle.area(4)}`); | |
| 16 | 15 | ``` | |
| 17 | 16 | ||
| 18 | - The contents of `circle.js`: | ||
| 17 | + On the first line, `foo.js` loads the module `circle.js` that is in the same | ||
| 18 | + directory as `foo.js`. | ||
| 19 | + | ||
| 20 | + Here are the contents of `circle.js`: | ||
| 19 | 21 | ||
| 20 | 22 | ```js | |
| 21 | 23 | const PI = Math.PI; | |
| 22 | 24 | ||
| 23 | 25 | exports.area = (r) => PI * r * r; | |
| 24 | 26 | ||
| 25 | 27 | exports.circumference = (r) => 2 * PI * r; | |
| 26 | - | ||
| 27 | 28 | ``` | |
| 28 | 29 | ||
| 29 | 30 | The module `circle.js` has exported the functions `area()` and | |
| Back | FazBrowse Home | New Git URL |
0 commit comments