Command Line Interface (CLI)

Strapi comes with a full featured Command Line Interface (CLI) which lets you scaffold and manage your project in seconds.

strapi new

Create a new project.

  1. strapi new <name>
  2. options: [--no-run|--use-npm|--debug|--quickstart|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbname=<dbname> --dbusername=<dbusername> --dbpassword=<dbpassword> --dbssl=<dbssl> --dbauth=<dbauth> --dbforce]
  • strapi new <name>
    Generates a new project called <name> and installs the default plugins through the npm registry.

  • strapi new <name> —debug
    Will display the full error message if one is fired during the database connection.

  • strapi new <name> —quickstart
    Use the quickstart system to create your app.

  • strapi new <name> —quickstart —no-run
    Use the quickstart system to create your app, and do not start the application after creation.

  • strapi new <name> —dbclient=<dbclient> —dbhost=<dbhost> —dbport=<dbport> —dbname=<dbname> —dbusername=<dbusername> —dbpassword=<dbpassword> —dbssl=<dbssl> —dbauth=<dbauth> —dbforce

    Generates a new project called <name> and skip the interactive database configuration and initialize with these options.

    • <dbclient> can be mongo, postgres, mysql.
    • <dbssl> and <dbauth> are available only for mongo and are optional.
    • --dbforce Allows you to overwrite content if the provided database is not empty. Only available for postgres, mysql, and is optional.

strapi develop

Alias: dev

Start a Strapi application with autoReload enabled.

Strapi modifies/creates files at runtime and needs to restart when new files are created. To achieve this, strapi develop adds a file watcher and restarts the application when necessary.

  1. strapi develop
  2. options: [--no-build |--watch-admin |--browser ]
  • strapi develop
    Starts your application with the autoReload enabled
  • strapi develop —no-build
    Starts your application with the autoReload enabled and skip the administration panel build process
  • strapi develop —watch-admin
    Starts your application with the autoReload enabled and the front-end development server. It allows you to customize the administration panel.
  • strapi develop —watch-admin —browser ‘google chrome’
    Starts your application with the autoReload enabled and the front-end development server. It allows you to customize the administration panel. Provide a browser name to use instead of the default one, false means stop opening the browser.

TIP

You should never use this command to run a Strapi application in production.

strapi start

Start a Strapi application with autoReload disabled.

This commands is there to run a Strapi application without restarts and file writes (aimed at production usage). Certain features are disabled in the strapi start mode because they require application restarts.

Allowed environment variables:

PropertyDescriptionTypeDefault
STRAPI_HIDE_STARTUP_MESSAGEIf true then Strapi will not show startup message on boot. Values can be true or falsestringfalse
STRAPI_LOG_LEVELValues can be ‘fatal’, ‘error’, ‘warn’, ‘info’, ‘debug’, ‘trace’stringdebug
STRAPI_LOG_TIMESTAMPEnables or disables the inclusion of a timestamp in the log message. Values can be true or falsestringfalse
STRAPI_LOG_FORCE_COLORValues can be true or falsestringtrue
STRAPI_LOG_PRETTY_PRINTIf pino-pretty module will be used to format logs. Values can be true or falsestringtrue

strapi build

Builds your admin panel.

  1. strapi build
  2. options: [--no-optimization]
  • strapi build
    Builds the administration panel and minimizing the assets
  • strapi build —clean
    Builds the administration panel and delete the previous build and .cache folders
  • strapi build —no-optimization
    Builds the administration panel without minimizing the assets. The build duration is faster.

strapi configuration:dump

Alias: config:dump

Dumps configurations to a file or stdout to help you migrate to production.

The dump format will be a JSON array.

  1. strapi configuration:dump
  2. Options:
  3. -f, --file <file> Output file, default output is stdout
  4. -p, --pretty Format the output JSON with indentation and line breaks (default: false)

Examples

  • strapi configuration:dump -f dump.json
  • strapi config:dump --file dump.json
  • strapi config:dump > dump.json

All these examples are equivalent.

WARNING

When configuring your application you often enter credentials for third party services (e.g authentication providers). Be aware that those credentials will also be dumped into the output of this command. In case of doubt, you should avoid committing the dump file into a versioning system. Here are some methods you can explore:

  • Copy the file directly to the environment you want and run the restore command there.
  • Put the file in a secure location and download it at deploy time with the right credentials.
  • Encrypt the file before committing and decrypt it when running the restore command.

strapi configuration:restore

Alias: config:restore

Restores a configuration dump into your application.

The input format must be a JSON array.

  1. strapi configuration:restore
  2. Options:
  3. -f, --file <file> Input file, default input is stdin
  4. -s, --strategy <strategy> Strategy name, one of: "replace", "merge", "keep". Defaults to: "replace"

Examples

  • strapi configuration:restore -f dump.json
  • strapi config:restore --file dump.json -s replace
  • cat dump.json | strapi config:restore
  • strapi config:restore < dump.json

All these examples are equivalent.

Strategies

When running the restore command, you can choose from three different strategies:

  • replace: Will create missing keys and replace existing ones.
  • merge: Will create missing keys and merge existing keys with their new value.
  • keep: Will create missing keys and keep existing keys as is.

strapi admin:reset-user-password

Alias admin:reset-password

Reset an admin user’s password. You can pass the email and new password as options or set them interactivly if you call the command without passing the options.

Example

  1. strapi admin:reset-user-password --email=chef@strapi.io --password=Gourmet1234

Options

OptionTypeDescription
-e, —emailstringThe user email
-p, —passwordstringNew password for the user
-h, —helpdisplay help for command

strapi generate:api

Scaffold a complete API with its configurations, controller, model and service.

  1. strapi generate:api <name> [<attribute:type>]
  2. options: [--plugin <name>]
  • strapi generate:api <name>
    Generates an API called <name> in the ./api folder at the root of your project.

  • strapi generate:api <name> —draft-and-publish=true
    Generates an API called <name> in the ./api folder at the root of your project and enabled the draft/publish feature.

  • strapi generate:api <name> <attribute:type>
    Generates an API called <name> in the ./api folder at the root of your project. The model will already contain an attribute called <attribute> with the type property set to <type>.

    Example: strapi generate:api product name:string description:text price:integer

  • strapi generate:api <name> —plugin <plugin>
    Generates an API called <name> in the ./plugins/<plugin> folder.

    Example: strapi generate:api product --plugin content-manager

TIP

The first letter of the filename will be uppercase.

strapi generate:controller

Create a new controller.

  1. strapi generate:controller <name>
  2. options: [--api <name>|--plugin <name>]
  • strapi generate:controller <name>
    Generates an empty controller called <name> in the ./api/<name>/controllers folder.

    Example: strapi generate:controller category will create the controller at ./api/category/controllers/Category.js.

  • strapi generate:controller <name> —api <api>
    Generates an empty controller called <name> in the ./api/<api>/controllers folder.

    Example: strapi generate:controller category --api product will create the controller at ./api/product/controllers/Category.js.

  • strapi generate:controller <name> —plugin <plugin>
    Generates an empty controller called <name> in the ./plugins/<plugin>/controllers folder.

TIP

The first letter of the filename will be uppercase.

strapi generate:model

Create a new model.

  1. strapi generate:model <name> [<attribute:type>]
  2. options: [--api <name>|--plugin <name>|--draft-and-publish <boolean>]
  • strapi generate:model <name>
    Generates an empty model called <name> in the ./api/<name>/models folder. It will create two files. The first one will be <name>.js which contains your lifecycle callbacks and another <name>.settings.json that will list your attributes and options.

    Example: strapi generate:model category will create these two files ./api/category/models/Category.js and ./api/category/models/Category.settings.json.

  • strapi generate:model <name> <attribute:type>
    Generates an empty model called <name> in the ./api/<name>/models folder. The file <name>.settings.json will already contain a list of attribute with their associated <type>.

    Example: strapi generate:model category name:string description:text will create these two files ./api/category/models/Category.js and ./api/category/models/Category.settings.json. This last file will contain two attributes name with the type string and description with type text.

  • strapi generate:model <name> —api <api>
    Generates an empty model called <name> in the ./api/<api>/models folder.

    Example: strapi generate:model category --api product will create these two files:

    • ./api/product/models/Category.js
    • ./api/product/models/Category.settings.json.
  • strapi generate:model <name> —plugin <plugin>
    Generates an empty model called <name> in the ./plugins/<plugin>/models folder.

  • strapi generate:model <name> —draft-and-publish=true
    Generates an empty model called <name> in the ./plugins/<plugin>/models folder with the draft/publish feature enabled

TIP

The first letter of the filename will be uppercase.

strapi generate:service

Create a new service.

  1. strapi generate:service <name>
  2. options: [--api <name>|--plugin <name>]
  • strapi generate:service <name>
    Generates an empty service called <name> in the ./api/<name>/services folder.

    Example: strapi generate:service category will create the service at ./api/category/services/Category.js.

  • strapi generate:service <name> —api <api>
    Generates an empty service called <name> in the ./api/<api>/services folder.

    Example: strapi generate:service category --api product will create the service at ./api/product/services/Category.js.

  • strapi generate:service <name> —plugin <plugin>
    Generates an empty service called <name> in the ./plugins/<plugin>/services folder.

TIP

The first letter of the filename will be uppercase.

strapi generate:policy

Create a new policy.

  1. strapi generate:policy <name>
  2. options: [--api <name>|--plugin <name>]
  • strapi generate:policy <name>
    Generates an empty policy called <name> in the ./config/policies folder.

    Example: strapi generate:policy isAuthenticated will create the policy at ./config/policies/isAuthenticated.js.

  • strapi generate:policy <name> —api <api>
    Generates an empty policy called <name> in the ./api/<api>/config/policies folder. This policy will be scoped and only accessible by the <api> routes.

    Example: strapi generate:policy isAuthenticated --api product will create the policy at ./api/product/config/policies/isAuthenticated.js.

  • strapi generate:policy <name> —plugin <plugin>
    Generates an empty policy called <name> in the ./plugins/<plugin>/config/policies folder. This policy will be scoped and accessible only by the <plugin> routes.

strapi generate:plugin

Create a new plugin skeleton.

  1. strapi generate:plugin <name>
  • strapi generate:plugin <name>
    Generates an empty plugin called <name> in the ./plugins folder.

    Example: strapi generate:plugin user will create the plugin at ./plugins/user.

Please refer to the local plugins section to know more.

strapi install

Install a plugin in the project.

  1. strapi install <name>
  • strapi install <name>
    Installs a plugin called <name>.

    Example: strapi install graphql will install the plugin strapi-plugin-graphql

WARNING

Some plugins have admin panel integrations, your admin panel might have to be rebuilt. This can take some time.

strapi uninstall

Uninstall a plugin from the project.

  1. strapi uninstall <name>
  2. options [--delete-files]
  • strapi uninstall <name>
    Uninstalls a plugin called <name>.

    Example: strapi uninstall graphql will remove the plugin strapi-plugin-graphql

  • strapi uninstall <name> —delete-files
    Uninstalls a plugin called <name> and removes the files in ./extensions/name/

    Example: strapi uninstall graphql --delete-files will remove the plugin strapi-plugin-graphql and all the files in ./extensions/graphql

WARNING

Some plugins have admin panel integrations, your admin panel might have to be rebuilt. This can take some time.

strapi console

Start the server and eval commands in your application in real time.

  1. strapi console

strapi version

Print the current globally installed Strapi version.

  1. strapi version

strapi help

List CLI commands.

  1. strapi help