diff options
author | Guy Bedford <guybedford@gmail.com> | 2021-06-15 20:09:29 +0300 |
---|---|---|
committer | Guy Bedford <guybedford@gmail.com> | 2021-06-25 21:26:49 +0300 |
commit | f4d0a6a07bf72c556c5ba8e98b3b23327c273e80 (patch) | |
tree | bbc9c36d93f4868119d9d2a9bb776e003919d752 /doc/api/esm.md | |
parent | 44ecd418923310aafbef8c6ccf9a9920bcf7af85 (diff) |
doc: esm examples /w imports for process, Buffer
PR-URL: https://github.com/nodejs/node/pull/39043
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Diffstat (limited to 'doc/api/esm.md')
-rw-r--r-- | doc/api/esm.md | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/doc/api/esm.md b/doc/api/esm.md index 40cb34ee908..534addc3330 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -247,6 +247,7 @@ readFile('./foo.txt', (err, source) => { ```js import fs, { readFileSync } from 'fs'; import { syncBuiltinESMExports } from 'module'; +import { Buffer } from 'buffer'; fs.readFileSync = () => Buffer.from('Hello, ESM'); syncBuiltinESMExports(); @@ -819,8 +820,9 @@ globalThis.someInjectedProperty = 42; console.log('I just set some globals!'); const { createRequire } = getBuiltin('module'); +const { cwd } = getBuiltin('process'); -const require = createRequire(process.cwd() + '/<preload>'); +const require = createRequire(cwd() + '/<preload>'); // [...] `; } @@ -921,8 +923,9 @@ purposes. // coffeescript-loader.mjs import { URL, pathToFileURL } from 'url'; import CoffeeScript from 'coffeescript'; +import { cwd } from 'process'; -const baseURL = pathToFileURL(`${process.cwd()}/`).href; +const baseURL = pathToFileURL(`${cwd()}/`).href; // CoffeeScript files end in .coffee, .litcoffee or .coffee.md. const extensionsRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/; |