GeezerVison is showing github.com — doc: add review suggestions to require() · nodejs/node@dd5afbe
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/modules.md +16-1Lines changed: 16 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -552,7 +552,22 @@ added: v0.1.13 |
552 | 552 |
|
553 | 553 | * {Function} |
554 | 554 |
|
555 | | -To require modules. |
| 555 | +Used to import modules, `JSON`, and local files. Modules can be imported |
| 556 | +from `node_modules`. Local modules and JSON files can be imported using |
| 557 | +a relative path (e.g. `./`, `./foo`, `./bar/baz`, `../foo`) that will be |
| 558 | +resolved against the directory named by [`__dirname`][] (if defined) or |
| 559 | +the current working directory. |
| 560 | + |
| 561 | +```js |
| 562 | +// Importing a local module: |
| 563 | +const myLocalModule = require('./path/myLocalModule'); |
| 564 | + |
| 565 | +// Importing a JSON file: |
| 566 | +const jsonData = require('./path/filename.json'); |
| 567 | + |
| 568 | +// Importing a module from node_modules or Node.js built-in module: |
| 569 | +const crypto = require('crypto'); |
| 570 | +``` |
556 | 571 |
|
557 | 572 | #### require.cache |
558 | 573 | <!-- YAML |
|