Skip to main content
Execute scripts defined in the scripts section of package.json.

Usage

ant run <script> [args...]

Parameters

script
string
required
Name of the script defined in package.json scripts section.
args
string[]
Arguments to pass to the script. Can be preceded by -- for clarity.

Options

--verbose
boolean
Enable verbose output.

Examples

List available scripts

ant run
Output:
Usage: ant run <script> [args...]

Run a script from package.json

Available scripts:
  start          ant index.js
  dev            ant --watch src/index.js
  build          tsc && esbuild src/index.ts --bundle
  test           jest

Run a script

ant run build
Output:
$ tsc && esbuild src/index.ts --bundle
Built successfully!

Run with arguments

ant run test -- --coverage --verbose
Output:
$ jest --coverage --verbose
Test Suites: 3 passed, 3 total
Tests:       15 passed, 15 total

Run dev script

ant run dev
Output:
$ ant --watch src/index.js
Server started on port 3000

Script Definition

Define scripts in package.json:
{
  "scripts": {
    "start": "ant index.js",
    "dev": "ant --watch src/index.js",
    "build": "tsc",
    "test": "jest",
    "lint": "eslint src/**/*.js",
    "format": "prettier --write ."
  }
}

Script Environment

node_modules/.bin in PATH

Scripts automatically have access to binaries in node_modules/.bin:
{
  "scripts": {
    "build": "tsc",  // Uses node_modules/.bin/tsc
    "lint": "eslint src"  // Uses node_modules/.bin/eslint
  }
}

Environment Variables

Scripts have access to:
  • npm_package_* variables with package.json values
  • PATH includes node_modules/.bin

Exit Codes

The exit code from the script is propagated:
ant run test
# Exit code matches the test runner's exit code

Shorthand

You can also run scripts without the run command:
ant start
# Equivalent to: ant run start
This works when the script name doesn’t conflict with Ant commands.

Script Not Found

ant run nonexistent
Output:
Error: script 'nonexistent' not found in package.json
Try 'ant run' to list available scripts.
  • ant exec - Run commands from node_modules/.bin
  • ant file - Run JavaScript files directly

Build docs developers (and LLMs) love