Reference
CLI

CLI command reference

With this CLI utility, you can create a barebones Cube app, generate a data model, validate it, or generate a JSON web token.

You can also use the CLI utility to deploy your Cube application to Cube Cloud. This is one of supported ways of continuous deployment.

create

The create command generates a barebones Cube app.

Usage

npx cubejs-cli create APP-NAME -d DB-TYPE [-t TEMPLATE]
ParameterDescriptionValues
-d, --db-type <db-type>Preconfigure Cube app for selected database.postgres, mysql, athena, mongobi, bigquery, redshift, mssql, clickhouse, snowflake, presto, druid
-t, --template <template>Framework running Cube backend.docker (default)

Example

Create app called demo-app using default (docker) template and mysql database:

npx cubejs-cli create demo-app -d mysql

Create app called demo-app using express template and mysql database:

npx cubejs-cli create demo-app -t express -d mysql

generate

The generate command helps to build data models for existing database tables. You can only run generate from the Cube app directory. This command requires an active database connection.

Usage

npx cubejs-cli generate -t TABLE-NAMES
ParameterDescriptionValues
-t, --tables <tables>Comma delimited list of tables to generate data models for.TABLE-NAME-1,TABLE-NAME-2

Example

Generate data model files for tables orders and customers:

npx cubejs-cli generate -t orders,customers

validate

The validate command checks models in a Cube project for validation errors.

Usage

npx cubejs-cli validate

Example

Example of a Cube project with models that fail validation:

npx cubejs-cli validate
❌ Cube Schema validation failed

Cube Error ---------------------------------------

Orders cube: "dimensions.id" does not match any of the allowed types
Possible reasons (one of):
  * (dimensions.id.case) is required
  * (dimensions.id.latitude) is required
  * (dimensions.id.sql) is required
LineItems cube: Cube Orders doesn't exist

Need some help? -------------------------------------

  Ask this question in Cube Slack: https://slack.cube.dev
  Post an issue: https://github.com/cube-js/cube/issues

token

The token command generates a JWT Cube token. It either uses the value of the CUBEJS_API_SECRET environment variable or provided value with -s flag. You can only run token command from the Cube app directory.

Use these manually generated tokens in production with caution.
Please refer to the Security Guide for production security best practices.

Usage

npx cubejs-cli token -e TOKEN-EXPIRY -s SECRET -p FOO=BAR
ParameterDescriptionExample
-e, --expiry          Token expiry. Set to 0 for no expiry (default: "30 days")1 day, 30 days        
-s, --secretCube app secret. Also can be set via environment variable CUBEJS_API_SECRET-
-p, --payloadToken Payloadfoo=bar, userId=2

Example

Generate token with 1 day expiry and payload { 'appId': 1, 'userId': 2 }:

npx cubejs-cli token -e "1 day" -p appId=1 -p userId=2

deploy

The deploy command uploads your Cube application to Cube Cloud. You can only run this command from the Cube app directory.

Usage

npx cubejs-cli deploy --upload-env --directory PATH --token TOKEN
ParameterDescription
--upload-env      Optional. Upload the .env file to Cube Cloud
--token <token>Authentication token for Cube Cloud
--directory <path>Path to the Cube application directory

Example

Upload a Cube application from the current directory to Cube Cloud and pass its .env file as well:

npx cubejs-cli deploy --upload-env --directory ./ --token 56e2636272ffc9cd8c19e9d1e9ffb52f