Skip to content

Commit dd5afbe

Browse files
ErickWendeltargos
authored andcommitted
doc: add review suggestions to require()
PR-URL: #23605 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 83ddd3e commit dd5afbe

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

doc/api/modules.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,22 @@ added: v0.1.13
552552

553553
* {Function}
554554

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+
```
556571

557572
#### require.cache
558573
<!-- YAML

0 commit comments

Comments
 (0)