Skip to main content

qjs - QuickJS Interpreter

The qjs executable is the QuickJS JavaScript interpreter. It includes a simple standard library and an interactive REPL (Read-Eval-Print Loop).

Basic Usage

Running JavaScript Files

Interactive REPL

Evaluate Expressions

Command-Line Options

General Options

flag
Display help information and list all available options
string
Evaluate the given expression and exit
flag
Enter interactive REPL mode after running scripts or expressions
flag
Instantiate the interpreter and quit immediately (useful for testing)

Module Loading

flag
Load the file as an ES6 module (default=autodetect)
flag
Load the file as a classic JavaScript script (default=autodetect)
By default, qjs automatically detects whether to load a file as a module or script based on:
  • File extension (.mjs files are modules)
  • Content analysis (presence of import/export statements)
string
Include an additional file before running the main script
flag
Make the std, os, and bjson modules available globally to the script
This makes the modules accessible without imports:

Memory and Performance

string
Limit memory usage to N kilobytes (supports b, k, m, g suffixes)
string
Limit stack size to N kilobytes (supports b, k, m, g suffixes)
Setting memory or stack limits too low may cause scripts to fail with out-of-memory errors.

Debugging and Diagnostics

flag
Enable memory allocation tracing for debugging memory issues
flag
Dump memory usage statistics when the runtime exits
hex
Set debug dump flags (hexadecimal value). See Dump Flags below.

Compilation Options

string
Compile the JavaScript file into a standalone executableMust be used with -o to specify the output file.
string
Specify the output filename for standalone executables
string
Select the executable to use as the base for standalone builds (defaults to current qjs)

Dump Flags

The --dump-flags option accepts a hexadecimal value combining these flags:

Example: Debugging Memory Leaks

Environment Variables

hex
Set default dump flags via environment variable

Global Objects

The qjs interpreter adds several global objects to the JavaScript environment:

execArgv

Array containing all command-line arguments:

argv0

The first command-line argument (typically the script name):
Contains the QuickJS-ng version string:

gc()

Manually trigger garbage collection:

Examples

Run a Simple Script

Run with Standard Library

Debug Memory Usage

Interactive REPL with Preloaded Code

Compile to Standalone Executable

See Creating Standalone Executables for more details on compilation.

Exit Codes

  • 0 - Success
  • 1 - Script execution error or compilation failure
  • 2 - Runtime/context allocation failure

See Also