# Command Line Interface (CLI)

Strapi comes with a full featured Command Line Interface (CLI) which lets you scaffold and manage your project in seconds. The CLI works with both the yarn and npm package managers.

✋ CAUTION

Interactive commands such as strapi admin:create-user don't display prompts with npm. A fix for the npm package manager is anticipated by March 2023. In the meantime, consider using the yarn package manager.

✏️ NOTE

It is recommended to install Strapi locally only, which requires prefixing all of the following strapi commands with the package manager used for the project setup (e.g npm run strapi help or yarn strapi help) or a dedicated node package executor (e.g. npx strapi help).

To pass options with npm use the syntax: npm run strapi <command> -- --<option>

To pass options with yarn use the syntax: yarn run strapi <command> --<option>

# strapi new

Create a new project.

strapi new <name>

options: [--no-run|--use-npm|--debug|--quickstart|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbname=<dbname> --dbusername=<dbusername> --dbpassword=<dbpassword> --dbssl=<dbssl> --dbauth=<dbauth> --dbforce]
1
2
3
  • 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 postgres, mysql.
    • --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.

strapi develop
options: [--no-build |--watch-admin |--browser ]
1
2
  • 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.

️❗️ WARNING

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

# strapi start

Start a Strapi application with autoReload disabled.

This command is to run a Strapi application without restarts and file writes, primarily for use in production. Certain features such as the Content-type Builder are disabled in the strapi start mode because they require application restarts. The start command can be prefaced with environment variables to customize the application start.

# strapi build

Builds your admin panel.

strapi build

options: [--no-optimization]
1
2
3
  • strapi build
    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 watch-admin

Starts the admin server. Strapi should already be running with strapi develop.

strapi watch-admin
options: [--browser <name>]
1
2

# strapi export

Exports your project data. The default settings create a .tar file, compressed using gzip and encrypted using aes-128-ecb.

strapi export
1

The exported file is automatically named using the format export_YYYYMMDDHHMMSS with the current date and timestamp. Alternately, you can specify the filename using the -f or --file flag. The following table provides all of the available options as command line flags:

Option Type Description
‑‑no‑encrypt - Disables file encryption and disables the key option.
‑‑no‑compress - Disables file compression.
-k,
--key
string Passes the encryption key as part of the export command.
The --key option can't be combined with --no-encrypt.
-f,
--file
string Specifies the export filename. Do not include a file extension.
--exclude string Exclude data using comma-separated data types. The available types are: content, files, and config.
--only string Include only these data. The available types are: content, files, and config.
-h,
--help
- Displays help for the strapi export command.

Examples

# examples of strapi export:

# export your data with the default options and the filename myData (which will result in a file named myData.tar.gz.enc):
strapi export -f myData 
# exports your data without encryption:
strapi export --no-encrypt
# export your data and configuration but not media files:
strapi export --exclude files 
1
2
3
4
5
6
7
8

# strapi import

Imports data into your project. The imported data must originate from another Strapi application. You must pass the --file option to specify the filename and location for the import action.

Option Type Description
-k,
--key
string Provide the encryption key in the command instead of a subsequent prompt.
-f,
--file
string Path and filename with extension for the data to be imported.
--force - Automatically answers "yes" to all prompts, including potentially destructive requests.
‑‑exclude string Exclude data using comma-separated data types.
The available types are: content, files, and config.
--only string Include only these data. The available types are: content, files, and config.
-h,
--help
- Display the strapi import help commands.

Examples


# example of strapi import:

# import your data with the default parameters and pass an encryption key: 
strapi import -f <your-filepath-and-filename> --key my-key

# import your data forcing "yes" for all subsequent prompts:
strapi import -f <your-filepath-and-filename> --force

# import only your configuration: 
strapi import -f <your-filepath-and-filename> --only config

1
2
3
4
5
6
7
8
9
10
11
12

# 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.

strapi configuration:dump

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

Examples

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

All these examples are equivalent.

✋ CAUTION

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.

strapi configuration:restore

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

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:create-user

Alias admin:create

Creates an administrator. Administrator's first name, last name, email, and password can be:

  • passed as options
  • or set interactively if you call the command without passing any option.

Example

strapi admin:create-user --firstname=Kai --lastname=Doe --email=chef@strapi.io --password=Gourmet1234
1

Options

Option Type Description Required
-f, --firstname string The administrator's first name Yes
-l, --lastname string The administrator's last name No
-e, --email string The administrator's email Yes
-p, --password string New password for the administrator No
-h, --help display help for command

# 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 interactively if you call the command without passing the options.

Example

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

Options

Option Type Description
-e, --email string The user email
-p, --password string New password for the user
-h, --help display help for command

# strapi generate

Run a fully interactive CLI to generate APIs, controllers, content-types, plugins, policies, middlewares and services.

strapi generate
1

# strapi templates:generate

Create a template from the current Strapi project.

strapi templates:generate <path>
1
  • strapi templates:generate <path>
    Generates a Strapi template at <path>

    Example: strapi templates:generate ../strapi-template-name will copy the required files and folders to a template directory inside ../strapi-template-name

# strapi ts:generate-types

Generate TypeScript typings for the project schemas.

strapi ts:generate-types
1
  • strapi ts:generate-types --verbose
    Generate typings with the verbose mode enabled, displaying a detailed table of the generated schemas.
  • strapi ts:generate-types --silent or strapi ts:generate-types -s
    Generate typings with the silent mode enabled, completely removing all the logs in the terminal.
  • strapi ts:generate-types --out-dir <path> or strapi ts:generate-types -o <path>
    Generate typings specifying the output directory in which the file will be created.
  • strapi ts:generate-types --file <filename> or strapi ts:generate-types -f <filename>
    Generate typings specifying the name of the file to contain the types declarations.

# strapi routes:list

Display a list of all the available routes.

strapi routes:list
1

# strapi policies:list

Display a list of all the registered policies.

strapi policies:list
1

# strapi middlewares:list

Display a list of all the registered middlewares.

strapi middlewares:list
1

# strapi content-types:list

Display a list of all the existing content-types.

strapi content-types:list
1

# strapi hooks:list

Display a list of all the available hooks.

strapi hooks:list
1

# strapi controllers:list

Display a list of all the registered controllers.

# strapi services:list

Display a list of all the registered services.

strapi services:list
1

# strapi install

Install a plugin in the project.

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

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

✋ CAUTION

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.

strapi uninstall <name>

options [--delete-files]
1
2
3
  • 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

✋ CAUTION

  • In addition to the uninstall command you need to remove the plugin configuration from ./config/plugins.js.
  • Some plugins have admin panel integrations, your admin panel might have to be rebuilt. This can take some time.

# strapi telemetry:disable

Disable data collection for the project (see Usage Information).

strapi telemetry:disable
1

# strapi telemetry:enable

Re-enable data collection for the project after it was disabled (see Usage Information).

strapi telemetry:enable
1

# strapi console

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

strapi console
1

# strapi version

Print the current globally installed Strapi version.

strapi version
1

# strapi help

List CLI commands.

strapi help
1