From dd5afbe05f1b49c8d5ba2f832f9fd9914d8c1998 Mon Sep 17 00:00:00 2001 From: erickwendel Date: Fri, 12 Oct 2018 11:33:59 -0700 Subject: [PATCH] doc: add review suggestions to require() PR-URL: https://github.com/nodejs/node/pull/23605 Reviewed-By: Denys Otrishko Reviewed-By: Trivikram Kamat Reviewed-By: Gireesh Punathil Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Vse Mozhet Byt Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell --- doc/api/modules.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 59c589e83ac233..2475fa2755e6d3 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -552,7 +552,22 @@ added: v0.1.13 * {Function} -To require modules. +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 +resolved against the directory named by [`__dirname`][] (if defined) or +the current working directory. + +```js +// Importing a local module: +const myLocalModule = require('./path/myLocalModule'); + +// Importing a JSON file: +const jsonData = require('./path/filename.json'); + +// Importing a module from node_modules or Node.js built-in module: +const crypto = require('crypto'); +``` #### require.cache