diff options
author | James M Snell <jasnell@gmail.com> | 2017-04-26 10:16:12 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-04-28 07:57:11 -0700 |
commit | 71f22c842bc3f9e04ebf110461c42b07a304f352 (patch) | |
tree | d1daec18ab195946b98b0f9a1a2675e90c9c7eb2 /doc/api/modules.md | |
parent | f11d4a1556a5536d69c1ae524822a709689c46ac (diff) | |
download | android-node-v8-71f22c842bc3f9e04ebf110461c42b07a304f352.tar.gz android-node-v8-71f22c842bc3f9e04ebf110461c42b07a304f352.tar.bz2 android-node-v8-71f22c842bc3f9e04ebf110461c42b07a304f352.zip |
doc: replace uses of `you` and other style nits
Replace uses of the pronouns `you` and `your` throughout
the docs + other minor style nits
PR-URL: https://github.com/nodejs/node/pull/12673
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Diffstat (limited to 'doc/api/modules.md')
-rw-r--r-- | doc/api/modules.md | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/doc/api/modules.md b/doc/api/modules.md index 5f1cf96ebb..d09e58f5cb 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -28,17 +28,15 @@ exports.circumference = (r) => 2 * PI * r; ``` The module `circle.js` has exported the functions `area()` and -`circumference()`. To add functions and objects to the root of your module, -you can add them to the special `exports` object. +`circumference()`. Functions and objects are added to the root of a module +by specifying additional properties on the special `exports` object. Variables local to the module will be private, because the module is wrapped in a function by Node.js (see [module wrapper](#modules_the_module_wrapper)). In this example, the variable `PI` is private to `circle.js`. -If you want the root of your module's export to be a function (such as a -constructor) or if you want to export a complete object in one assignment -instead of building it one property at a time, assign it to `module.exports` -instead of `exports`. +The `module.exports` property can be assigned a new value (such as a function +or object). Below, `bar.js` makes use of the `square` module, which exports a constructor: @@ -66,8 +64,8 @@ The module system is implemented in the `require('module')` module. <!-- type=misc --> When a file is run directly from Node.js, `require.main` is set to its -`module`. That means that you can determine whether a file has been run -directly by testing `require.main === module`. +`module`. That means that it is possible to determine whether a file has been +run directly by testing `require.main === module`. For a file `foo.js`, this will be `true` if run via `node foo.js`, but `false` if run by `require('./foo')`. @@ -91,10 +89,10 @@ Let's say that we wanted to have the folder at `/usr/lib/node/<some-package>/<some-version>` hold the contents of a specific version of a package. -Packages can depend on one another. In order to install package `foo`, you -may have to install a specific version of package `bar`. The `bar` package -may itself have dependencies, and in some cases, these dependencies may even -collide or form cycles. +Packages can depend on one another. In order to install package `foo`, it +may be necessary to install a specific version of package `bar`. The `bar` +package may itself have dependencies, and in some cases, these may even collide +or form cyclic dependencies. Since Node.js looks up the `realpath` of any modules it loads (that is, resolves symlinks), and then looks for their dependencies in the `node_modules` @@ -203,8 +201,8 @@ executed multiple times. This is an important feature. With it, "partially done" objects can be returned, thus allowing transitive dependencies to be loaded even when they would cause cycles. -If you want to have a module execute code multiple times, then export a -function, and call that function. +To have a module execute code multiple times, export a function, and call +that function. ### Module Caching Caveats @@ -297,8 +295,8 @@ a done in main, a.done=true, b.done=true ``` -If you have cyclic module dependencies in your program, make sure to -plan accordingly. +Careful planning is required to allow cyclic module dependencies to work +correctly within an application. ## File Modules @@ -391,8 +389,8 @@ this order: This allows programs to localize their dependencies, so that they do not clash. -You can require specific files or sub modules distributed with a module by -including a path suffix after the module name. For instance +It is possible to require specific files or sub modules distributed with a +module by including a path suffix after the module name. For instance `require('example-module/path/to/file')` would resolve `path/to/file` relative to where `example-module` is located. The suffixed path follows the same module resolution semantics. @@ -425,9 +423,10 @@ Additionally, Node.js will search in the following locations: Where `$HOME` is the user's home directory, and `$PREFIX` is Node.js's configured `node_prefix`. -These are mostly for historic reasons. **You are highly encouraged -to place your dependencies locally in `node_modules` folders.** They -will be loaded faster, and more reliably. +These are mostly for historic reasons. + +*Note*: It is strongly encouraged to place dependencies in the local +`node_modules` folder. These will be loaded faster, and more reliably. ## The module wrapper @@ -438,7 +437,7 @@ wrapper that looks like the following: ```js (function(exports, require, module, __filename, __dirname) { -// Your module code actually lives in here +// Module code actually lives in here }); ``` @@ -488,7 +487,7 @@ The `module.exports` object is created by the Module system. Sometimes this is not acceptable; many want their module to be an instance of some class. To do this, assign the desired export object to `module.exports`. Note that assigning the desired object to `exports` will simply rebind the local `exports` variable, -which is probably not what you want to do. +which is probably not what is desired. For example suppose we were making a module called `a.js` @@ -566,7 +565,7 @@ To illustrate the behavior, imagine this hypothetical implementation of function require(/* ... */) { const module = { exports: {} }; ((module, exports) => { - // Your module code here. In this example, define a function. + // Module code here. In this example, define a function. function someFunc() {} exports = someFunc; // At this point, exports is no longer a shortcut to module.exports, and @@ -628,7 +627,7 @@ added: v0.5.1 The `module.require` method provides a way to load a module as if `require()` was called from the original module. -Note that in order to do this, you must get a reference to the `module` +*Note*: In order to do this, it is necessary to get a reference to the `module` object. Since `require()` returns the `module.exports`, and the `module` is typically *only* available within a specific module's code, it must be explicitly exported in order to be used. |