File tree 1 file changed +5
-4
lines changed
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments