diff options
Diffstat (limited to 'std/node/README.md')
-rw-r--r-- | std/node/README.md | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/std/node/README.md b/std/node/README.md index 6d363a11d..14c245809 100644 --- a/std/node/README.md +++ b/std/node/README.md @@ -5,3 +5,20 @@ This module is meant to have a compatibility layer for the **Warning** : Any function of this module should not be referred anywhere in the deno standard library as it's a compatiblity module. + +## CommonJS Module Loading + +`createRequire(...)` is provided to create a `require` function for loading CJS +modules. + +```ts +import { createRequire } from "https://deno.land/std/node/module.ts"; + +const require_ = createRequire(import.meta.url); +// Loads native module polyfill. +const path = require_("path"); +// Loads extensionless module. +const cjsModule = require_("./my_mod"); +// Visits node_modules. +const leftPad = require_("left-pad"); +``` |