How to Try Code Examples
If you want to tinker with examples, you have many options on how to run the code:
At the time of writing, native Node ES Modules support is still flaky, using plain repl call like node leave-only-html.js
would not work — we have to use esm
which we call via -r
flag like this: node -r esm leave-only-html.js
.
If you
git clone
the monorepo andnpm i
and thencd
into the package's folder, you can execute each example file using a Node repl, for example:node -r esm leave-only-html.js
. If there are no errors, nothing should happen — asserts succeeded!The
package.json
of each program has an npm scripttest:examples
which calls the example test runner which gives some UI in the terminal, you get feedback of each example testing outcome. To run it,cd
into a package's folder in cloned monorepo andnpm run test:examples
.You can use CodeSandbox — copy-paste the example code into the sandbox, manually adding all imported dependencies.
You could use Runkit , but it doesn't support ES Modules (
import
), so you'd have to replace all imports with CommonJS equivalents, withconst foo = require("bar")
.