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 same realm that runs .jsh scripts (see man jsh). The runtime provides console, process, module, and fetch as bare globals, plus a working require(). Code can be provided inline with -e, from a script file on the virtual filesystem, or piped via stdin.
There is no bare fs or exec global. Use require('fs') for file access (an async-only VFS bridge — see man jsh for the full method list) and require('sliccy:exec') for shelling out through the WASM bash interpreter. require() also resolves real npm packages (fetched from esm.sh CDN — run ipk install <pkg> first) and the rest of the sliccy:<name> capability-module scheme (skill, http, browser, usb, serial, hid, cli, color, time, fmt, pool — full details in man jsh). 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 fs = require('fs'); const data = await fs.promises.readFile('/workspace/data.json', 'utf8'); console.log(data)"
Read a file from the virtual filesystem using the fs module.
$ node -e "const exec = require('sliccy:exec'); const r = await exec('ls -la'); console.log(r.stdout)"
Run a shell command from within a node script using the sliccy:exec capability module.
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. require() works (both real npm packages and the sliccy: scheme), but Node built-in modules like child_process, net, and crypto are mostly not available. 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.