Skip to main content

CLI Reference

The tjs binary is the entry point to txiki.js. It runs scripts, evaluates expressions, serves HTTP applications, runs tests, bundles and compiles code, and provides an interactive REPL.

tjs [options] [subcommand] [args]

Run tjs --help for a summary, or tjs <subcommand> --help-style usage by invoking a subcommand with missing arguments.

Global options

These options apply before the subcommand:

OptionDescription
-v, --versionPrint the version (v<version>) and exit
-h, --helpPrint help and exit
--memory-limit LIMITSet the memory limit (in bytes) for the JavaScript runtime
--stack-size SIZEMaximum JavaScript stack size, in bytes (default: 1024 KB)
--wasm-stack-size SIZEWebAssembly stack size, in bytes (default: 512 KB)
--tls-ca FILEPath to a custom CA bundle PEM file (overrides the embedded Mozilla bundle)

Subcommands

tjs run

Run a JavaScript program.

tjs run app.js
OptionDescription
--import-map FILEPath to an import map JSON file

If the file ends in .wasm, tjs run acts as a WASI runner instead of evaluating JavaScript.

tjs eval

Evaluate a JavaScript expression passed on the command line:

tjs eval "console.log(1 + 1)"

tjs serve

Serve an HTTP (or HTTPS) application from a module that default-exports a fetch handler:

tjs serve app.js

See the Serving HTTP guide for the module shape, WebSocket support, and TLS options.

tjs test

Run every test-*.js file in a directory (defaults to the current directory). Each test runs as a separate tjs run subprocess.

tjs test tests/

The test runner is tuned with environment variables:

VariableDescription
VERBOSE_TESTSWhen set, print verbose output
TJS_TEST_TIMEOUTPer-test timeout in milliseconds (default 30000)
TJS_TEST_CONCURRENCYNumber of tests to run in parallel (default: navigator.hardwareConcurrency)

tjs bundle

Bundle a JavaScript/TypeScript file (and its imports) into a single file using esbuild.

tjs bundle app.js bundle.js

See the Code Bundling guide for options and details.

tjs compile

Compile a single JavaScript file into a self-contained standalone executable.

tjs compile bundle.js

See the Standalone Executables guide.

tjs app

Manage TPK app packages — multi-file applications packaged into a .tpk archive or a standalone executable.

tjs app init # scaffold a new app
tjs app pack # package into a .tpk file
tjs app compile # compile into a standalone executable

The REPL

Running tjs with no subcommand on a TTY starts an interactive read-eval-print loop with syntax-highlighted output and persistent command history.

tjs

Lines starting with . are directives rather than JavaScript:

DirectiveDescription
.helpPrint the directive list
.timeToggle display of evaluation timing
.strictToggle strict-mode evaluation
.depth NSet the object inspection depth (default 2)
.hiddenToggle display of non-enumerable properties
.colorToggle colored output
.darkSelect the dark color theme
.lightSelect the light color theme
.clearClear the terminal
.clear-historyClear the command history
.load FILELoad and evaluate source from a file
.quitExit the REPL

The toggle directives (.time, .strict, .hidden, .color) accept an optional boolean argument, e.g. .color yes. Command history is persisted to $TJS_HOME/history.db (see environment variables); on builds compiled without SQLite, history is silently disabled.

Reading a script from stdin

When tjs is run with no subcommand and stdin is not a TTY, it reads the entire input and evaluates it as a script. This makes tjs convenient in pipelines:

echo "console.log('hi')" | tjs
tjs < script.js

Running WASI modules

When the argument to tjs run ends in .wasm, txiki.js instantiates it as a WASI module against wasi_snapshot_preview1. The current directory (.) and the filesystem root (/) are pre-opened, any trailing arguments are forwarded to the module as WASI arguments, and the guest's exit code becomes the process exit code.

tjs run module.wasm arg1 arg2

For programmatic control over WASI, use the tjs:wasi module directly.

Environment variables

VariableDescription
TJS_HOMEOverrides the home/cache directory (default ~/.tjs). Stores the HTTP cookie jar (cookies.txt), the cached esbuild binary (esbuild/<version>/), and the REPL history database (history.db).
TJS_CA_BUNDLEPath to a custom TLS CA bundle PEM file.
SSL_CERT_FILEFallback path to a custom TLS CA bundle PEM file.

The CA bundle is resolved with the precedence --tls-ca > TJS_CA_BUNDLE > SSL_CERT_FILE > the embedded Mozilla bundle.

Outbound HTTP requests also honor the standard proxy environment variables — see the HTTP Proxy Support guide.