From 3f2a01688ddd641630d0424b27c4efc746e00ba7 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 6bac6a8b23144b..95890f773e9958 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -551,7 +551,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