File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,27 @@ ECMAScript modules are [the official standard format][] to package JavaScript
13
13
code for reuse. Modules are defined using a variety of [ ` import ` ] [ ] and
14
14
[ ` export ` ] [ ] statements.
15
15
16
+ The following example of an ES module exports a function:
17
+
18
+ ``` js
19
+ // addTwo.js
20
+ function addTwo (num ) {
21
+ return num + 2 ;
22
+ }
23
+
24
+ export { addTwo };
25
+ ```
26
+
27
+ The following example of an ES module imports the function from ` addTwo.js ` :
28
+
29
+ ``` js
30
+ // app.js
31
+ import { addTwo } from ' ./addTwo.js' ;
32
+
33
+ // Prints: 6
34
+ console .log (addTwo (4 ));
35
+ ```
36
+
16
37
Node.js fully supports ECMAScript modules as they are currently specified and
17
38
provides limited interoperability between them and the existing module format,
18
39
[ CommonJS] [ ] .
You can’t perform that action at this time.
0 commit comments