qjs - QuickJS Interpreter
Theqjs 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 (
.mjsfiles are modules) - Content analysis (presence of
import/exportstatements)
string
Include an additional file before running the main script
flag
Make the This makes the modules accessible without imports:
std, os, and bjson modules available globally to the scriptMemory 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)
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
Theqjs 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):
navigator.userAgent
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
Exit Codes
0- Success1- Script execution error or compilation failure2- Runtime/context allocation failure
See Also
- qjsc - QuickJS compiler for generating C code
- Creating Standalone Executables - Guide to creating standalone binaries