node and js: a
bare ES2023 engine in WebAssembly, inside the Mirage process, for small
scripts and pipe transforms. It is not Node: there is no require, npm,
fs or fetch. The files it opens are the workspace’s, under the same
mount modes and permissions as shell commands. It is in the default runtimes
of both SDKs.
Installation
- Python
- TypeScript
qjs-wasi.wasm from a
quickjs-ng release.
Point home, or MIRAGE_QUICKJS_HOME, at its directory.Usage
QuickJS is in the default runtimes, sonode works once it is installed. To
list it yourself:
- Python
- TypeScript
- YAML
What is wired
std and os are globals, as in qjs --std.
In TypeScript, any
std or os function not listed as supported throws
TypeError.
Notes
-e <code>runs the argument, a file runs a mounted script, and with neither, piped input is the program. A.mjsfile runs as an ES module;.jsand-erun as classic scripts, and-mforces module mode.console.logandprintadd a newline;std.out.putsandstd.err.putswrite raw.- QuickJS cannot reach host files or the network, but only
command_limitsbound its CPU and memory. Run untrusted or heavy code in a sandbox. - QuickJS can evaluate expressions, so it can run a
route policy:
route_policy: ./policy.jsruns per line withctxas a global, and the last expression names the runtime.