ant binary is the single entry point for running scripts, starting the REPL, evaluating inline code, and managing packages. Every interaction starts here. This page covers all flags, execution modes, and the subcommands Ant exposes for package management.
Basic usage
--.
process.argv contains ["ant", "script.js", "arg1", "arg2"]. Without --, anything after the file is interpreted by Ant itself rather than forwarded to your script.
Execution modes
Ant supports four distinct execution modes depending on how you invoke it.Run a file
Inline eval
Use-e / --eval to run a short snippet without creating a file.
-p / --print to evaluate an expression and print the result to stdout:
Stdin mode
Pipe a script through stdin and Ant will execute it. This is useful for scripting and one-liners.-p here too.
REPL
Runant with no arguments to start the interactive REPL. See REPL for details.
Flags
Evaluate the given script string directly. The script runs as if it were an inline file. Combine with
--print to output the result.Evaluate the script and print the return value to stdout. Works with both
--eval and stdin mode. Non-undefined values are pretty-printed; strings are printed as-is.Restart the process automatically when the entry file changes on disk. Cannot be combined with
--eval, stdin mode, or subcommands. See Watch mode.When using
--watch, keep previous output visible instead of clearing the terminal on each restart. Must be used together with --watch; using it alone is an error.Set the file path used to persist
localStorage data between runs. By default localStorage is in-memory only and lost when the process exits.Print full version information and exit.
Print just the bare version number and exit. Useful for scripts that need to compare or parse the version string.
Print the help message listing all flags and subcommands, then exit.
Enable verbose output for package manager operations. Has no effect during normal script execution.
Disable all ANSI color codes in Ant’s output. Set this when piping output to tools that don’t handle escape sequences.
Override the JavaScript stack size in kilobytes. The default is derived from the operating system thread stack size. Increase this if you hit stack overflow errors in deeply recursive code.
--verbose, --no-color, and --stack-size are consumed by Ant before argument parsing and are not passed through to your script.Package manager subcommands
Ant includes a built-in package manager. Pass a subcommand name as the first positional argument. Each subcommand is covered in detail in the Package Manager section.| Subcommand | Alias | Description |
|---|---|---|
init | — | Create a new package.json |
install | i | Install dependencies from lockfile |
update | up | Re-resolve dependencies and refresh lockfile |
add | a | Add a package to dependencies |
remove | rm | Remove a package from dependencies |
trust | — | Run lifecycle scripts for packages |
run | — | Run a script from package.json |
exec | x | Run a command from node_modules/.bin |
why | explain | Show why a package is installed |
info | — | Show package information from registry |
ls | list | List installed packages |
cache | — | Manage the package cache |
create | — | Scaffold a project from a template |