Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add docs to require() #23605

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions doc/api/modules.md
Expand Up @@ -552,16 +552,20 @@ added: v0.1.13

* {Function}

Used to import modules, `JSON` and local files. Modules can be imported from `node_modules`. Local modules and JSON files can be imported using the pattern `'./'`.
Used to import modules, `JSON`, and local files. Modules can be imported
from `node_modules`. Local modules and JSON files can be imported using
a relative path (e.g. `./`, `./foo`, `./bar/baz`, `../foo`) that will be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we perhaps also note that path-resolution is OS independent (given that we are providing examples in Linux/Unix flavor)?

Copy link
Member

@BridgeAR BridgeAR Oct 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lundibundi I think that would be a good addition but it could also land in a separate PR?

resolved against the directory named by [`__dirname`][] (if defined) or
the current working directory.

```js
// importing localModule
// Importing a local module:
const myLocalModule = require('./path/myLocalModule');

// importing JSON file
// Importing a JSON file:
const jsonData = require('./path/filename.json');

// importing module from node_modules or Node.js internals
// Importing a module from node_modules or Node.js built-in module:
const crypto = require('crypto');
```

Expand Down