Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
🧑🏽‍🔬 We're testing new AI and search tools ondocs-next.strapi.io! Feel free to have a look andshare your feedback
  • API calls
  • CRON jobs
  • Environment variables
  • Features
  • Middlewares
  • Plugins
  • Server
  • 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 theyarn andnpm package managers.

    Caution

    Interactive commands such asstrapi admin:create-user don't display prompts withnpm. A fix for thenpm package manager is anticipated by March 2023. In the meantime, consider using theyarn package manager.

    Note

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

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

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

    ℹ️ Strapi v4 CLI commands removed from Strapi 5:

    Thestrapi install,strapi uninstall,strapi new, andstrapi watch-admin commands from Strapi v4 have been removed in Strapi 5:

    Strapi v4 commandStrapi 5 equivalent
    strapi install [plugin]Use the npx command corresponding to the plugin (found on the Marketplace, seeMarketplace)
    strapi newUse the equivalent yarn or npx command to create a new Strapi project (seeCLI installation guide)
    strapi watch-adminyarn develop ornpm run develop always starts the Strapi server in "watch-admin" mode. To disable this in Strapi 5, runyarn develop --no-watch-admin ornpm run develop --no-watch-admin.

    strapi develop

    Alias:dev

    Start a Strapi application with auto-reloading 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 also adds middlewares to support HMR (Hot Module Replacement) for the administration panel. This allows you to customize the administration panel without having to restart the application or run a separate server.

    strapi develop
    options:[--no-build|--no-watch-admin|--browser|--debug|--silent]
    • strapi develop --open
      Starts your application with auto-reloading enabled & open your default browser with the administration panel running.
    • strapi develop --no-watch-admin
      Prevents the server from auto-reload when changes are made to the admin panel code.
    • [DEPRECATED]strapi develop --no-build
      Starts your application with the auto-reloading enabled and skip the administration panel build process
    • [DEPRECATED]strapi develop --watch-admin
      Starts your application with the auto-reloading enabled and the front-end development server. It allows you to customize the administration panel.
    • [DEPRECATED]strapi develop --watch-admin --browser 'google chrome'
      Starts your application with the auto-reloading 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 auto-reloading 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 thestrapi start mode because they require application restarts. Thestart command can be prefaced withenvironment variables to customize the application start.

    strapi build

    Builds your admin panel.

    strapi build
    OptionTypeDescription
    -d, --debug-Enable debugging mode with verbose logs (default: false)
    --minify-Minify the output (default: true)
    --no-optimization-[DEPRECATED]: use minify instead
    --silent-Don't log anything (default: false)
    --sourcemaps-Produce sourcemaps (default: false)
    --stats-Print build statistics to the console (default: false)

    strapi login

    Logs in to Strapi Cloud (seeCloud CLI documentation).

    strapi logout

    Logs out from Strapi Cloud (seeCloud CLI documentation).

    strapi deploy

    Deploys to Strapi Cloud (seeCloud CLI documentation).

    strapi export

    Exports your project data. The default settings create a.tar file, compressed usinggzip and encrypted usingaes-128-ecb.

    strapiexport

    The exported file is automatically named using the formatexport_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:

    OptionTypeDescription
    --no-encrypt-Disables file encryption and disables thekey option.
    --no-compress-Disables file compression.
    -k,
    --key
    stringPasses the encryption key as part of theexport command.
    The--key option can't be combined with--no-encrypt.
    -f,
    --file
    stringSpecifies the export filename. Do not include a file extension.
    --excludestringExclude data using comma-separated data types. The available types are:content,files, andconfig.
    --onlystringInclude only these data. The available types are:content,files, andconfig.
    -h,
    --help
    -Displays help for thestrapi export command.

    Examples

    Examples of strapi export:
    # export your data with the default options and the filename myData, which results in a file named myData.tar.gz.enc.
    strapiexport-f myData

    # export your data without encryption.
    strapiexport --no-encrypt

    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.

    strapiimport
    OptionTypeDescription
    -k,--keystringProvide the encryption key in the command instead of a subsequent prompt.
    -f,--filestringPath and filename with extension for the data to be imported.
    -h,--help-Display thestrapi import help commands.

    Examples

    Example of strapi import:

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

    strapi transfer

    Transfers data between 2 Strapi instances. This command is primarily intended for use between a local instance and a remote instance or 2 remote instances. Thetransfer command requires a Transfer token, which is generated in the destination instance Admin panel. See theUser Guide for detailed documentation on creating Transfer tokens.

    Caution

    The destination Strapi instance should be running with thestart command and not thedevelop command.

    OptionDescription
    --to [destinationURL]Full URL of the/admin endpoint on the destination Strapi instance
    (e.g.--to https://my-beautiful-strapi-website/admin)
    --to-token [transferToken]Transfer token for the remote Strapi destination
    --from [sourceURL]Full URL of the/admin endpoint of the remote Strapi instance to pull data from
    (e.g.,--from https://my-beautiful-strapi-website/admin)
    ‑‑from‑tokenTransfer token from the Strapi source instance.
    --forceAutomatically answer "yes" to all prompts, including potentially destructive requests, and run non-interactively.
    --excludeExclude data using comma-separated data types. The available types are:content,files, andconfig.
    --onlyInclude only these data. The available types are:content,files, andconfig.
    -h,--helpDisplays the commands forstrapi transfer.
    Caution

    Either--to or--from is required, but it's not currently allowed to enter both or neither.

    Example

    strapi transfer--to http://example.com/admin --to-token my-transfer-token

    strapi report

    Prints out debug information useful for debugging and required when reporting an issue.

    OptionDescription
    -u,--uuidIncludes the project UUID
    -d,--dependenciesIncludes project dependencies
    --allLogs all the data

    Examples

    To include the project UUID and dependencies in the output:

    strapi report--uuid--dependencies

    To log everything, use the--all option:

    strapi report--all

    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)

    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"

    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

    Aliasadmin: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

    Options

    OptionTypeDescriptionRequired
    -f, --firstnamestringThe administrator's first nameYes
    -l, --lastnamestringThe administrator's last nameNo
    -e, --emailstringThe administrator's emailYes
    -p, --passwordstringNew password for the administratorNo
    -h, --helpdisplay help for command

    strapi admin:reset-user-password

    Aliasadmin: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

    Options

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

    strapi generate

    Generate APIs,controllers,content-types,policies,middlewares,services, andmigrations.

    strapi generate

    The command displays an interactive menu with the following options:

    • api - Generate a new API with controller and service
    • controller - Generate a new controller
    • content-type - Generate a new content type with schema
    • policy - Generate a new policy
    • middleware - Generate a new middleware
    • migration - Generate a new database migration
    • service - Generate a new service

    strapi generate GIF

    The generator detects TypeScript or JavaScript automatically and creates files with the correct extension (.ts or.js).Generated files include commented examples. Singular and plural names must be different and use kebab-case format.

    API generator

    Creates an API withcontroller andservice files.

    Generated file:controllers/[name].js|ts,services/[name].js|ts, androutes/[name].js|ts (standard APIs only)

    Content-type generator

    Creates a content type schema with optional API files.

    Available attribute types

    TypeDescription
    stringShort text
    textLong text
    richtextRich text editor
    emailEmail field
    passwordPassword field
    integerWhole number
    bigintegerLarge whole number
    floatDecimal number
    decimalPrecise decimal
    dateDate only
    timeTime only
    datetimeDate and time
    timestampUnix timestamp
    booleanTrue/false
    jsonJSON data
    enumerationPredefined values
    mediaFile upload

    Generated files

    ConditionGenerated files
    Content type onlycontent-types/[name]/schema.json
    With API bootstrap
    • content-types/[name]/schema.json
    • controllers/[name].js|ts
    • services/[name].js|ts
    • routes/[name].js|ts

    Controller generator

    Creates acontroller file with basic action structure.

    Generated file:controllers/[name].js|ts

    Service generator

    Creates aservice file with basic structure.

    Generated file:services/[name].js|ts

    Policy generator

    Creates apolicy file for access control.

    Generated file:policies/[name].js|ts

    Middleware generator

    Creates amiddleware file for request processing.

    Generated file:middlewares/[name].js|ts

    Migration generator

    Creates a timestampedmigration file.

    Generated file:database/migrations/[timestamp].[name].js|ts

    Configuration options

    Thestrapi generate interactive CLI may offer various configuration options depending on the chosen Strapi element to generate:

    Destination choices

    When creating a content-type, controller, policy, middleware, or service, you can choose its destination:

    OptionDescription
    New APICreates a new API folder
    Existing APIAdds to existing API folder
    Existing pluginAdds to existing plugin folder
    RootAdds to project root (policies and middlewares only)

    Content-type specific options

    When creating a content-type, you can choose to create a collection type or a single type (seeContent-Type Builder documentation for differences):

    TypeDescriptionExample
    Collection TypeFor multiple entriesArticles, users
    Single TypeFor a single entryHomepage, settings

    You will also have to define various types of names. The following table explains their differences. Only the display name needs to be manually defined, and you can press Enter to accept the default suggested name for the singular and plural names. Singular and plural names matter for API endpoints (seeREST API documentation for details):

    FieldFormatDescriptionExample
    Display nameHuman-readableName shown in admin panelBlog Post
    Singular nameKebab-caseUsed for API endpointsblog-post
    Plural nameKebab-caseUsed for collectionsblog-posts

    strapi templates:generate

    Create a template from the current Strapi project.

    strapi templates:generate<path>
    • 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 atemplate directory inside../strapi-template-name

    strapi ts:generate-types

    GenerateTypeScript typings for the project schemas.

    strapi ts:generate-types
    • strapi ts:generate-types --debug
      Generate typings with the debug mode enabled, displaying a detailed table of the generated schemas.
    • strapi ts:generate-types --silent orstrapi ts:generate-types -s
      Generate typings with the silent mode enabled, completely removing all the logs in the terminal. Cannot be combined withdebug
    • strapi ts:generate-types --out-dir <path> orstrapi ts:generate-types -o <path>
      Generate typings specifying the output directory in which the file will be created.
    Caution

    Strapi requires the project types to be generated in thetypes directory for them to work. The--out-dir option should not be used for most cases. However, it can be useful for cases such as generating a second copy to compare the difference between your existing and updated types after changing your content structure.

    strapi routes:list

    Display a list of all the availableroutes.

    strapi routes:list

    strapi policies:list

    Display a list of all the registeredpolicies.

    strapi policies:list

    strapi middlewares:list

    Display a list of all the registeredmiddlewares.

    strapi middlewares:list

    strapi content-types:list

    Display a list of all the existingcontent-types.

    strapi content-types:list

    strapi hooks:list

    Display a list of all the available hooks.

    strapi hooks:list

    strapi controllers:list

    Display a list of all the registeredcontrollers.

    strapi controllers:list

    strapi services:list

    Display a list of all the registeredservices.

    strapi services:list

    strapi telemetry:disable

    Disable data collection for the project (seeUsage Information).

    strapi telemetry:disable

    strapi telemetry:enable

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

    strapi telemetry:enable

    strapi console

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

    strapi console

    strapi version

    Print the currently installed Strapi version.It will output the current globally installed version if this command is strapi is installed globally, or the current version of Strapi within a Strapi project if the command is run from a given folder containing a Strapi project.

    strapi version

    strapi help

    List CLI commands.

    strapihelp

    [8]ページ先頭

    ©2009-2025 Movatter.jp