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

Incomplete documentation require() #23106

Closed
soulne4ny opened this issue Sep 26, 2018 · 4 comments
Closed

Incomplete documentation require() #23106

soulne4ny opened this issue Sep 26, 2018 · 4 comments
Labels
doc Issues and PRs related to the documentations. module Issues and PRs related to the module subsystem. question Issues that look for answers.

Comments

@soulne4ny
Copy link

Incomplete documentation at https://nodejs.org/dist/latest-v8.x/docs/api/modules.html#modules_require
It states no use cases.

require() is widely used for reading .json files.
Is it safe to apply require() over .json? Are there any guarantees that .json file is allowed to contain single JSON object only? Are there any guarantees require()ing a .json file containing valid JS code will never lead to interpreting the code?

@mscdex
Copy link
Contributor

mscdex commented Sep 26, 2018

The complete process for resolving modules describes what happens: https://nodejs.org/dist/latest-v8.x/docs/api/modules.html#modules_all_together

  1. If X.json is a file, parse X.json to a JavaScript Object. STOP

The code for the module loader verifies this behavior.

@Fishrock123 Fishrock123 added question Issues that look for answers. doc Issues and PRs related to the documentations. module Issues and PRs related to the module subsystem. labels Sep 26, 2018
@Fishrock123
Copy link
Contributor

As noted above, this behavior is specified. That being said, just "To require modules." is practically not even documentation. it should be expanded in some way regardless.

@Trott
Copy link
Member

Trott commented Nov 18, 2018

Docs were expanded in #23605.

@Trott Trott closed this as completed Nov 18, 2018
@soulne4ny
Copy link
Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. module Issues and PRs related to the module subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

4 participants