Run JavaScript code using a Node.js-compatible shim in the browser

Synopsis

node -e <code> [args...]

node <script.js> [args...]

echo "code" | node

Description

Executes JavaScript code in a sandboxed Node.js-compatible environment inside SLICC. The runtime provides shims for console, process, fs, require, module, and exec. Code can be provided inline with -e, from a script file on the virtual filesystem, or piped via stdin.

The fs bridge supports readFile, readFileBinary, writeFile, writeFileBinary, readDir, exists, and fetchToFile. The exec bridge lets scripts run shell commands through the WASM interpreter. The process shim provides argv, env, cwd(), exit(), stdout.write(), and stderr.write().

Options

-e <code>, --eval <code> Execute the given JavaScript code inline

-v, --version Print the Node.js shim version (v20.0.0-js-shim)

-h, --help Show usage information

Examples

$ node -e "console.log('hello')"

Execute inline JavaScript and print to stdout.

$ node script.js arg1 arg2

Run a script file from the virtual filesystem with arguments available via process.argv.

$ echo "console.log(2+2)" | node

Pipe code through stdin.

$ node -e "const data = await fs.readFile('/workspace/data.json'); console.log(data)"

Read a file from the virtual filesystem using the fs bridge.

$ node -e "const r = await exec('ls -la'); console.log(r.stdout)"

Run a shell command from within a node script using the exec bridge.

Notes

This is not a full Node.js runtime. It runs JavaScript via AsyncFunction construction (or a sandbox iframe in extension mode) with shimmed globals. Native Node.js modules and require() are not supported — calling require() throws an error. Top-level await is supported. REPL mode (running node with no arguments) is not available.

The runtime reports version v20.0.0-js-shim to indicate it is a browser-based shim, not native Node.js. Global state persists across invocations within the same shell session via __state.

See Also

python3, commands