NocoBase CTL is a command-line tool for managing and controlling NocoBase applications. Its relationship with multiple NocoBase App instances is shown below:
+----------------------+
| NocoBase CTL |
| Controller |
+----------------------+
|
+----------------+----------------+
| | |
v v v
+----------------+ +----------------+ +----------------+
| NocoBase App | | NocoBase App | | NocoBase App |
| Dev | | Test | | Prod |
+----------------+ +----------------+ +----------------+
NocoBase CTL combines:
- built-in commands for environment management and generic resource access
- runtime-generated commands loaded from your NocoBase application's Swagger schema
This allows the CLI to stay aligned with the target application instead of relying on a fixed command list.
Install NocoBase CTL globally:
npm install -g @nocobase/ctl@latestAdd an environment:
nocobase-ctl env add --name local --base-url http://localhost:13000/apiAdd an environment with an API key:
nocobase-ctl env add --name local --base-url http://localhost:13000/api --token <api-key>Authenticate an environment with OAuth:
nocobase-ctl env auth -e localShow the current environment:
nocobase-ctl envList configured environments:
nocobase-ctl env listSwitch the current environment:
nocobase-ctl env use localUpdate the runtime command cache from swagger:get:
nocobase-ctl env update
nocobase-ctl env update -e localUse the generic resource commands:
nocobase-ctl resource list --resource users
nocobase-ctl resource get --resource users --filter-by-tk 1
nocobase-ctl resource create --resource users --values '{"nickname":"Ada"}'When you execute a runtime command, the CLI will:
- resolve the target environment
- read the application's Swagger schema from
swagger:get - generate or reuse a cached runtime command set for that application version
- execute the requested command
If the API documentation plugin is disabled, the CLI will prompt to enable it.
Use -e, --env to temporarily select an environment:
nocobase-ctl env update -e prod
nocobase-ctl resource list --resource users -e prodThis does not change the current environment unless you explicitly run:
nocobase-ctl env use <name>The env command supports two config scopes:
project: use./.nocobase-ctlin the current working directoryglobal: use the global.nocobase-ctldirectory
Use -s, --scope to select one explicitly:
nocobase-ctl env list -s project
nocobase-ctl env add -s global --name prod --base-url http://example.com/api --token <api-key>
nocobase-ctl env auth -e prod -s global
nocobase-ctl env use local -s projectIf you do not pass --scope, the CLI uses automatic resolution:
- current working directory if
./.nocobase-ctlexists NOCOBASE_HOME_CLI- your home directory
Current built-in topics:
envresource
Check available commands at any time:
nocobase-ctl --help
nocobase-ctl env --help
nocobase-ctl resource --help-e, --env: temporary environment selection-s, --scope: config scope forenvcommands--role: role override, sent asX-Role-t, --token: API key override-j, --json-output: print raw JSON response
Example:
nocobase-ctl env update -e prod -s global
nocobase-ctl resource list --resource users -e prod -j
nocobase-ctl resource list --resource users -e prod --role adminThe CLI stores its local state in .nocobase-ctl, including:
config.json: environment definitions and current selectionversions/<version>/commands.json: cached runtime commands for a generated version