### Start the example application Source: https://github.com/strapi/strapi/blob/develop/CONTRIBUTING.md Start the getstarted example application. ```bash cd ./examples/getstarted yarn develop ``` -------------------------------- ### Install dependencies and setup Source: https://github.com/strapi/strapi/blob/develop/CONTRIBUTING.md Navigate to the repository root and run the setup commands, including linking AI skills. ```bash cd strapi yarn install yarn setup yarn ai:sync # link AI skills into your local tool directories (.agents/, .claude/, .cursor/) ``` -------------------------------- ### Install dependencies and start LikeC4 dev server Source: https://github.com/strapi/strapi/blob/develop/architecture/README.md Run from the architecture directory. Installs pinned dependencies and starts the dev server, which watches all .c4 and .likec4 files. ```bash cd architecture yarn install --immutable yarn dev ``` -------------------------------- ### Typical migration workflow - start v4 project Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Step 3: Start v4 project in a separate terminal using the path printed by setup. v4 will automatically start its database if needed. ```bash cd yarn develop:postgres ``` -------------------------------- ### Create and start a prod app Source: https://github.com/strapi/strapi/wiki/Switch-from-dev-app-to-prod Creates a new prod app and starts it to see your modifications. Run after the setup:build completes successfully. ```bash # In a new terminal window $ cd sandbox $ strapi new my-prod-app $ cd my-prod-app && strapi start ``` -------------------------------- ### Create and start a dev app Source: https://github.com/strapi/strapi/wiki/Switch-from-dev-app-to-prod Creates a dev app with the --dev flag, starts the database and Strapi server, then starts the front-end server to modify the admin. Run in a new terminal window after the setup is completed. ```bash # In a new terminal window $ mkdir sandbox && cd sandbox # Create a dev app $ strapi new my-app --dev # Start your db $ mongod # Start the strapi server $ cd sandbox/my-app && strapi start # Start the front-end server to make modify the front-end # In a new terminal window $ cd sandbox/my-app/admin && npm start ``` -------------------------------- ### Initial monorepo setup commands Source: https://github.com/strapi/strapi/blob/develop/AGENTS.md Run once after cloning to install dependencies, build all packages, and link AI skills. `yarn setup` cleans and builds all packages and hints to run `ai:sync` if links are missing; `yarn ai:sync` links `.ai/skills` into `.agents/`, `.claude/`, and `.cursor/`. ```bash # Initial setup (run once after cloning) yarn install yarn setup # clean + build all packages; hints to run ai:sync if links are missing yarn ai:sync # link .ai/skills into .agents/ .claude/ .cursor/ ``` -------------------------------- ### Install v4 dependencies Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md One-time installation of v4 project dependencies. Use the path printed by setup. ```bash cd yarn install ``` -------------------------------- ### Clone and setup Strapi repository Source: https://github.com/strapi/strapi/wiki/Switch-from-dev-app-to-prod Clones the Strapi repository and runs the setup command to install the dev environment. Requires Node.js v10.10.0, npm 6.4.1, and a database like MongoDB or PostgreSQL. ```bash # In a terminal window clone the strapi repository $ mkdir repositories && cd repositories $ git clone git@github.com:strapi/strapi.git && cd strapi $ npm run setup ``` -------------------------------- ### Install with yarn Source: https://github.com/strapi/strapi/blob/develop/packages/providers/email-nodemailer/README.md Install the provider using yarn. ```bash yarn add @strapi/provider-email-nodemailer ``` -------------------------------- ### Install with npm Source: https://github.com/strapi/strapi/blob/develop/packages/providers/email-nodemailer/README.md Install the provider using npm. ```bash npm install @strapi/provider-email-nodemailer --save ``` -------------------------------- ### Build plugin admin Source: https://github.com/strapi/strapi/wiki/Switch-from-dev-app-to-prod Builds the plugin's admin by running the setup command with the --plugins flag inside the dev app where the plugin is installed. ```bash $ cd sandbox/my-app $ npm run setup --plugins ``` -------------------------------- ### Typical migration workflow - start v5 server Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Step 7: Start v5 server with the same database. Migrations will run automatically on startup. ```bash yarn develop:postgres ``` -------------------------------- ### Guided Tour Initial State Example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/admin/guided-tour.md Example of the initial state object for the guided tour, showing a contentManager tour with currentStep 0 and isCompleted false, enabled true, and a completedActions array. ```typescript const initialState = { tours: { contentManager: { currentStep: 0, isCompleted: false, }, }, enabled: true, completedActions: ['didCreateSchema'], }; ``` -------------------------------- ### Start v4 project Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Starts the v4 project with the specified database. Options: postgres, mysql, mariadb, sqlite. ```bash yarn develop:postgres # or :mysql, :mariadb, :sqlite ``` -------------------------------- ### Run the dev sandbox with SQLite, PostgreSQL, or MySQL Source: https://github.com/strapi/strapi/blob/develop/AGENTS.md Starts the development sandbox. Default uses SQLite; for PostgreSQL or MySQL, first start the non-memory database containers with `docker-compose -f docker-compose.dev.yml up -d`, then run with the corresponding `DB` environment variable. ```bash # Run the dev sandbox cd examples/getstarted yarn develop # SQLite (default) # Start non-memory databases (postgres/mysql) docker-compose -f docker-compose.dev.yml up -d DB=postgres yarn develop # PostgreSQL DB=mysql yarn develop # MySQL ``` -------------------------------- ### Run example app with admin watch Source: https://github.com/strapi/strapi/blob/develop/CONTRIBUTING.md Run the example application while watching the admin panel. ```bash cd ./examples/getstarted yarn develop --watch-admin ``` -------------------------------- ### Manual install with npm global Source: https://github.com/strapi/strapi/blob/develop/packages/cli/create-strapi-app/README.md Install the create-strapi-app CLI globally using npm, then run it to create a new project. Replace 'my-app' with your desired project name. ```bash npm install -g create-strapi-app create-strapi-app my-app ``` -------------------------------- ### Install @strapi/provider-upload-cloudinary Source: https://github.com/strapi/strapi/blob/develop/packages/providers/upload-cloudinary/README.md Install the Cloudinary upload provider using either yarn or npm. ```bash # using yarn yarn add @strapi/provider-upload-cloudinary # using npm npm install @strapi/provider-upload-cloudinary --save ``` -------------------------------- ### Install @strapi/provider-upload-local Source: https://github.com/strapi/strapi/blob/develop/packages/providers/upload-local/README.md Install the local upload provider package using either yarn or npm. ```bash # using yarn yarn add @strapi/provider-upload-local # using npm npm install @strapi/provider-upload-local --save ``` -------------------------------- ### Manual install with yarn global Source: https://github.com/strapi/strapi/blob/develop/packages/cli/create-strapi-app/README.md Install the create-strapi-app CLI globally using yarn, then run it to create a new project. Replace 'my-app' with your desired project name. ```bash yarn global add create-strapi-app create-strapi-app my-app ``` -------------------------------- ### transferEntities Implementation Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/data-transfer/01-engine/02-stream-lifecycle.md TypeScript example showing how to create read, transform, progress tracker, and write streams for a transfer stage, then start the transfer. ```typescript async transferEntities(): Promise { const stage: TransferStage = 'entities'; // 1. Create read stream from source const source = await this.sourceProvider.createEntitiesReadStream?.(); // 2. Create transform stream for data modifications const transform = this.#createStageTransformStream(stage); // 3. Create progress tracker const tracker = this.#progressTracker(stage); // 4. Create write stream from destination const destination = await this.destinationProvider.createEntitiesWriteStream?.(); // 5. Start the transfer await this.#transferStage({ stage, source, destination, transform, tracker }); } ``` -------------------------------- ### Install @strapi/permissions with yarn Source: https://github.com/strapi/strapi/blob/develop/packages/core/permissions/README.md Install the @strapi/permissions package using yarn. ```sh yarn add @strapi/permissions ``` -------------------------------- ### logDefaultStartupMessage() output example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/startup-logger.mdx Default message displayed when the Strapi server is started, showing available actions and URLs for the admin panel and server. ```text Actions available Welcome back! To manage your project πŸš€, go to the administration panel at: http://localhost:1337/admin To access the server ⚑️, go to: http://localhost:1337 ``` -------------------------------- ### cron.start() example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/cron.mdx Starts the cron service and schedules all cron jobs. Returns `this`. ```javascript const { createCronService } = require('packages/core/strapi/lib/services/cron.js'); const cron = createCronService(); const task = () => { console.log('Task executed!'); }; cron.add({ myTask: { task, options: '*/5 * * * *', // Executes every 5 minutes. }, }); cron.start(); ``` -------------------------------- ### Install Playwright browsers Source: https://github.com/strapi/strapi/blob/develop/docs/docs/contributing/03-testing/e2e/00-setup.md Install the required Playwright browsers (Chromium and WebKit) before running e2e tests. ```shell npx playwright install chromium webkit ``` -------------------------------- ### Run migration performance benchmark Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Complete workflow for benchmarking v4β†’v5 migration performance: setup, seed, baseline, candidate, and comparison. Requires one-time setup and rebuilds of @strapi/database and @strapi/core before capturing candidates. ```bash # One-time setup yarn setup:v4 cd ../../complex-v4 && yarn install && cd - # Seed data (one snapshot per DB Γ— multiplier, kept in snapshots/) yarn bench:seed --db postgres --multiplier 100 # Capture baseline β€” on develop (or whatever you're comparing against) yarn bench:run --db postgres --multiplier 100 --label baseline # Capture candidate β€” git checkout or cherry-pick the PR, rebuild, then: yarn workspace @strapi/database run build yarn workspace @strapi/core run build yarn bench:run --db postgres --multiplier 100 --label pr-xxxxx # Generate matrix comparison report yarn bench:compare --baseline baseline --candidate pr-xxxxx ``` -------------------------------- ### Install @strapi/provider-email-sendgrid Source: https://github.com/strapi/strapi/blob/develop/packages/providers/email-sendgrid/README.md Install the SendGrid email provider package using either yarn or npm. ```bash # using yarn yarn add @strapi/provider-email-sendgrid # using npm npm install @strapi/provider-email-sendgrid --save ``` -------------------------------- ### Install @strapi/provider-upload-aws-s3 Source: https://github.com/strapi/strapi/blob/develop/packages/providers/upload-aws-s3/README.md Install the AWS S3 upload provider using either yarn or npm. ```bash # using yarn yarn add @strapi/provider-upload-aws-s3 # using npm npm install @strapi/provider-upload-aws-s3 --save ``` -------------------------------- ### Setup with Git worktrees Source: https://github.com/strapi/strapi/blob/develop/CONTRIBUTING.md Set up a checkout created with Git worktrees. ```bash git worktree add cd yarn setup:worktree ``` -------------------------------- ### Install @strapi/provider-email-sendmail Source: https://github.com/strapi/strapi/blob/develop/packages/providers/email-sendmail/README.md Install the provider package using either Yarn or npm. The two commands are alternative package manager choices for the same installation step. ```bash yarn add @strapi/provider-email-sendmail ``` ```bash npm install @strapi/provider-email-sendmail --save ``` -------------------------------- ### Run admin panel in development mode Source: https://github.com/strapi/strapi/blob/develop/CONTRIBUTING.md Start the administration panel server for development. ```bash cd ./packages/core/admin yarn watch ``` -------------------------------- ### Simplified Database Commands in Bash Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Starts Strapi with the specified database. The command starts a database container if needed (no-op for SQLite), configures Strapi automatically, starts the dev server, and keeps the database running after Ctrl+C. Default ports: PostgreSQL 5432, MySQL 3306, MariaDB host 3307 (override with POSTGRES_PORT, MYSQL_PORT, MARIADB_PORT). ```bash yarn develop:postgres # PostgreSQL container + Strapi dev server yarn develop:mysql # MySQL container + Strapi dev server yarn develop:mariadb # MariaDB container + Strapi dev server yarn develop:sqlite # SQLite file (no container) + Strapi dev server ``` -------------------------------- ### Create and use a Container with add and get Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/container.mdx Shows how to instantiate a Container, register a config object with add, and retrieve it with get. The resolver can be a function or any value; if a function, it is executed on first get. ```javascript const container = new Container(); container.add('config', { get: (configName) => {}, set: (configName, value) => {}, }); const dbConfig = container.get('config').get('database'); ``` -------------------------------- ### Start databases with docker-compose Source: https://github.com/strapi/strapi/blob/develop/examples/getstarted/README.md Starts the databases defined in the docker-compose.dev.yml file at the root of the monorepo. Run this command from the root of the monorepo. ```bash docker-compose -f docker-compose.dev.yml up -d ``` -------------------------------- ### Install @strapi/provider-email-amazon-ses with yarn and npm Source: https://github.com/strapi/strapi/blob/develop/packages/providers/email-amazon-ses/README.md Install the provider package using either yarn or npm. The commands are shown as alternatives; choose one based on your package manager. ```bash # using yarn yarn add @strapi/provider-email-amazon-ses # using npm npm install @strapi/provider-email-amazon-ses --save ``` -------------------------------- ### Integration example: engine, domain, and providerFactory Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/permissions/index.md Shows how to set up the permission engine with action and condition providers, register a custom condition, create permissions, generate an ability, and evaluate a permission. Requires @strapi/permissions and @strapi/utils. The example uses a custom 'isOwner' condition and a 'read' action on the 'article' subject. ```typescript import { engine, domain } from '@strapi/permissions'; import { providerFactory } from '@strapi/utils'; // 1. Define Providers const providers = { action: providerFactory(), condition: providerFactory(), }; // 2. Register Custom Conditions providers.condition.register({ name: 'isOwner', handler: (ctx) => ctx.user.id === ctx.resource.ownerId, }); // 3. Create Engine const permissionEngine = engine.new({ providers }); // 4. Define Permissions const permissions = [ domain.permission.create({ action: 'read', subject: 'article', conditions: ['isPublished'], }), domain.permission.create({ action: 'update', subject: 'article', conditions: ['isOwner'], properties: { fields: ['title', 'content'], }, }), ]; // 5. Generate Ability const ability = await permissionEngine.generateAbility(permissions); // 6. Evaluate Permission const canReadArticle = ability.can('read', 'article'); ``` -------------------------------- ### Install @strapi/plugin-sentry Source: https://github.com/strapi/strapi/blob/develop/packages/plugins/sentry/README.md Install the Sentry plugin using either Yarn or NPM. Choose one command based on your package manager. ```sh yarn add @strapi/plugin-sentry ``` ```sh npm install @strapi/plugin-sentry ``` -------------------------------- ### Run E2E tests with Playwright Source: https://github.com/strapi/strapi/blob/develop/docs/docs/contributing/03-testing/index.md E2E tests use Playwright and specs live in `tests/e2e/tests/` in one folder per domain (e.g., `admin`, `content-manager`, `i18n`). `yarn playwright install` is a one-time browser install. Use `--setup --concurrency=1` to run all domains sequentially, `--domains` to select specific domains, and `--concurrency` to run multiple domains in parallel. ```bash yarn playwright install # one-time browser install yarn test:e2e --setup --concurrency=1 # run all domains one after the other yarn test:e2e --domains content-manager admin # run some domains yarn test:e2e --concurrency=3 # run three domains in parallel ``` -------------------------------- ### Setup v4 project Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Creates a Strapi v4 project outside the monorepo. Override location with V4_OUTSIDE_DIR. ```bash yarn setup:v4 ``` -------------------------------- ### Build admin panel with Yarn or NPM Source: https://github.com/strapi/strapi/blob/develop/packages/plugins/color-picker/README.md After installing the plugin, build the admin panel to include the color picker. Use either Yarn or NPM commands. ```sh # Using Yarn yarn build # Or using NPM npm run build ``` -------------------------------- ### Install @strapi/provider-email-mailgun Source: https://github.com/strapi/strapi/blob/develop/packages/providers/email-mailgun/README.md Install the Mailgun email provider package using either yarn or npm. ```bash yarn add @strapi/provider-email-mailgun ``` ```bash npm install @strapi/provider-email-mailgun --save ``` -------------------------------- ### Start Strapi with autoReload (develop) Source: https://github.com/strapi/strapi/blob/develop/examples/empty/README.md Starts the Strapi application with autoReload enabled. Use this during development to see changes reflected immediately. ```bash npm run develop # or yarn develop ``` -------------------------------- ### Using the useGuidedTour Hook Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/admin/guided-tour.md Shows how to use the useGuidedTour hook to access state and dispatch, and how to dispatch a 'next_step' action. ```tsx import { useGuidedTour } from './Context'; const MyComponent = () => { const state = useGuidedTour('MyComponent', (s) => s.state); const dispatch = useGuidedTour('MyComponent', (s) => s.dispatch); const currentTour = state.tours.myNewTour; const isEnabled = state.enabled; const completedActions = state.completedActions; // Dispatch actions const handleNext = () => { dispatch({ type: 'next_step', payload: 'myNewTour' }); }; }; ``` -------------------------------- ### strapi.start() Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/Strapi.mdx Starts the Strapi application. Returns a Promise. ```APIDOC ## strapi.start() ### Description Starts the Strapi application. Returns a Promise. ### Returns - Promise ``` -------------------------------- ### strapi.listen() Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/Strapi.mdx Starts the server. Returns a Promise. ```APIDOC ## strapi.listen() ### Description Starts the server. Returns a Promise. ### Returns - Promise ``` -------------------------------- ### plugins.js configuration example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/core/configuration/00-intro.md Example of a plugins.js configuration file that exports a function returning an object. The values are accessible via strapi.config.get('plugin::graphql.endpoint') and this configuration is not strictly typed or loaded from environment variables. ```JavaScript module.exports = () => ({ graphql: { enabled: true, config: { endpoint: '/graphql', defaultLimit: 25, maxLimit: 100, depthLimit: 10, apolloServer: { tracing: true, }, }, }, }); ``` -------------------------------- ### Install plugin in dev app Source: https://github.com/strapi/strapi/wiki/Switch-from-dev-app-to-prod Creates a symbolic link to the plugin in the dev app's plugins folder so you can modify it. ```bash # Navigate to the dev app (generated with the --dev flag) $ cd sandbox/my-app/plugins $ ln -s ../../../repositories/my-plugin ./ ``` -------------------------------- ### Example JSON Transform script for Strapi upgrade Source: https://github.com/strapi/strapi/blob/develop/packages/utils/upgrade/README.md Called for every JSON file in a user's project. Must return the JSON object (modified or not) to pass to the next transform. This example targets the root package.json and updates the @strapi/strapi dependency to 5.0.0. ```typescript import path from 'node:path'; import type { JSONTransform } from '../../..'; const transform: JSONTransform = (file, params) => { // Extract the json api and the cwd so we can target specific files const { cwd, json } = params; // To target only a root level package.json file: const rootPackageJsonPath = path.join(cwd, 'package.json'); if (file.path !== rootPackageJsonPath) { // Return the json object unmodified to pass it to the next transform return file.json; } // Use json() to get useful helpers for performing your transform const j = json(file.json); const strapiDepAddress = 'dependencies.@strapi/strapi'; // if this file contains a value at dependencies.@strapi/strapi if (j.has(strapiDepAddress)) { // we set the value to 5.0.0 j.set(strapiDepAddress, '5.0.0'); } // at the end we must return the modified json object return j.root(); }; export default transform; ``` -------------------------------- ### Example response from /admin/users/me/permissions Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/admin/permissions/02-frontend/fetching-permissions.md Shows the JSON structure returned by the /admin/users/me/permissions endpoint. Each permission has an id, action, subject, properties, and conditions. The example includes permissions for admin API tokens and content-manager explorer actions with fields and locales. ```json { "data": [ { "id": 426, "action": "admin::api-tokens.access", "subject": null, "properties": {}, "conditions": [] }, { "id": 427, "action": "admin::api-tokens.regenerate", "subject": null, "properties": {}, "conditions": [] }, { "id": 763, "action": "plugin::content-manager.explorer.create", "subject": "api::homepage.homepage", "properties": { "fields": ["title", "slug", "single", "multiple"], "locales": ["en", "fr"] }, "conditions": [] }, { "id": 765, "action": "plugin::content-manager.explorer.read", "subject": "api::homepage.homepage", "properties": { "fields": ["title", "slug", "single", "multiple"], "locales": ["en", "fr"] }, "conditions": [] }, { "id": 767, "action": "plugin::content-manager.explorer.update", "subject": "api::homepage.homepage", "properties": { "fields": ["title", "slug", "single", "multiple"], "locales": ["en", "fr"] }, "conditions": [] } ] } ``` -------------------------------- ### Typical migration workflow - create snapshot Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Step 5: Create a snapshot of the database. ```bash cd examples/complex yarn db:snapshot:postgres mybackup ``` -------------------------------- ### runCLI() Source: https://github.com/strapi/strapi/blob/develop/packages/generators/generators/README.md Starts the generator CLI. This function launches the interactive command-line interface for generating Strapi code. ```APIDOC ## runCLI() ### Description Starts the generator CLI. This function launches the interactive command-line interface for generating Strapi code. ### Method runCLI ### Parameters None ### Returns None ``` -------------------------------- ### Install @strapi/plugin-color-picker with Yarn or NPM Source: https://github.com/strapi/strapi/blob/develop/packages/plugins/color-picker/README.md Add the color picker plugin as an NPM dependency to your Strapi application. Use either Yarn or NPM commands. ```sh # Using Yarn yarn add @strapi/plugin-color-picker # Or using NPM npm install @strapi/plugin-color-picker ``` -------------------------------- ### Quick usage with npx Source: https://github.com/strapi/strapi/blob/develop/packages/cli/create-strapi/README.md Use npx to run the create-strapi CLI directly without installing it globally. The @latest tag ensures the most recent version is used. ```sh npx create-strapi@latest ``` -------------------------------- ### Example commit messages Source: https://github.com/strapi/strapi/blob/develop/AGENTS.md Examples of valid commit messages following the Conventional Commits format. Use 'yarn commit' for an interactive prompt and run 'yarn version:check' if package.json files are modified. ```bash feat(content-manager): add bulk delete action fix(database): preserve relation order during publish chore(admin): migrate data-fetching to react-query ``` -------------------------------- ### cron.start() Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/cron.mdx Starts the cron service and schedules all the cron jobs. ```APIDOC ## cron.start() ### Description Starts the cron service and schedules all the cron jobs. ### Returns - `this` - The cron service instance for chaining. ### Request Example ```javascript const { createCronService } = require('packages/core/strapi/lib/services/cron.js'); const cron = createCronService(); const task = () => { console.log('Task executed!'); }; cron.add({ myTask: { task, options: '*/5 * * * *', // Executes every 5 minutes. }, }); cron.start(); ``` ``` -------------------------------- ### Example commit messages Source: https://github.com/strapi/strapi/blob/develop/CONTRIBUTING.md Illustrates valid commit messages following the convention. For `fix` commits, the message should explain what the commit fixes, not the solution. ```text feat: introduce document service ``` ```text fix: unable to publish documents due to missing permissions ``` ```text chore: refactor data-fetching in EditView to use react-query ``` ```text docs: document service API reference ``` -------------------------------- ### Lodash get Usage Example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/contributing/04-frontend-guidelines.md Shows a common use of lodash's get function to extract a deep attribute from a schema. The guidelines discourage adding lodash functions and suggest using optional chaining or restructuring data instead. ```jsx import get from 'lodash/get'; const extractDeepAttribute = (schema: object, path: string[]) => { return get(schema, ['attributes', ...path], {}); }; ``` -------------------------------- ### Configure v4 project Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Copy .env.example to .env and edit as needed for custom DB credentials. ```bash cp .env.example .env # Edit .env as needed ``` -------------------------------- ### Repository structure tree Source: https://github.com/strapi/strapi/blob/develop/AGENTS.md Shows the top-level layout of the Strapi monorepo, including packages, examples, docs, and tests directories. ```text packages/core/ # Framework: strapi, admin, database, content-manager, types, utils… packages/plugins/ # Official plugins: users-permissions, i18n, graphql, documentation… packages/providers/ # Email + upload provider implementations packages/utils/ # Shared tooling: logger, eslint-config, tsconfig, vitest-config packages/cli/ # CLI tools: create-strapi-app, cloud-cli examples/ # Dev sandboxes only β€” not published, not for production fixes docs/ # Contributor docs site (contributor.strapi.io); package docs mirror packages/ under docs/docs/packages/ tests/ # Integration, E2E, and CLI test infrastructure ``` -------------------------------- ### Per-message OAuth2: shared transporter and send as specific user Source: https://github.com/strapi/strapi/blob/develop/packages/providers/email-nodemailer/README.md Two-part example for per-message OAuth2 (multi-user). First configures a shared transporter with OAuth2 credentials in config/plugins.js, then sends an email on behalf of a specific user by passing user-specific auth tokens in the send call. Requires the nodemailer OAuth2 setup. ```javascript // config/plugins.js - shared transporter with OAuth2 module.exports = ({ env }) => ({ email: { config: { provider: 'nodemailer', providerOptions: { host: 'smtp.gmail.com', port: 465, secure: true, auth: { type: 'OAuth2', clientId: env('OAUTH_CLIENT_ID'), clientSecret: env('OAUTH_CLIENT_SECRET'), }, }, settings: { defaultFrom: 'noreply@example.com', defaultReplyTo: 'support@example.com', }, }, }, }); ``` ```javascript // Send as a specific user await strapi .plugin('email') .service('email') .send({ to: 'recipient@example.com', subject: 'Hello from user', text: 'Sent on behalf of a specific user', auth: { user: 'specific-user@gmail.com', refreshToken: userRefreshToken, accessToken: userAccessToken, }, }); ``` -------------------------------- ### Basic UID parameter example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/types/type-system/02-concepts/02-uid.md Declares a function that takes a UID.ContentType parameter and returns a Data.ContentType. Shows a common usage pattern for fetching an entity based on a resource UID. ```typescript import type { UID, Data } from '@strapi/types'; declare function fetch(uid: UID.ContentType): Data.ContentType; ``` -------------------------------- ### Guided Tour Actions Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/admin/guided-tour.md Actions that can be dispatched to the guided tour reducer to manage tour state. ```APIDOC ## Guided Tour Actions ### Description Actions that can be dispatched to the guided tour reducer to manage tour state. ### Actions - `next_step` - Advance to the next step in a tour - `previous_step` - Go back to the previous step in a tour - `go_to_step` - Go to a specific step - `skip_tour` - Mark a tour as completed (skipped) - `skip_all_tours` - Disable all tours globally - `reset_all_tours` - Reset all tours to initial state - `set_completed_actions` - Update the list of completed user actions ### Usage Dispatch actions using the `dispatch` function from `useGuidedTour`: ```tsx dispatch({ type: 'next_step', payload: 'myNewTour' }); ``` ``` -------------------------------- ### logStats() output example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/startup-logger.mdx Displays startup information about the Strapi instance, including time launched, launch duration, environment, process PID, version, edition, and database. ```text Project information β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Time β”‚ Wed Jan 01 2000 00:00:01 GMT+0200 (Central Euro… β”‚ β”‚ Launched in β”‚ 2000 ms β”‚ β”‚ Environment β”‚ development β”‚ β”‚ Process PID β”‚ 42 β”‚ β”‚ Version β”‚ 4.9.0 (node v18.12.1) β”‚ β”‚ Edition β”‚ Enterprise β”‚ β”‚ Database β”‚ postgres β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` -------------------------------- ### cron.add() example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/cron.mdx Adds cron tasks to the service. Each key is a task name; values can be a function (key used as cron expression) or an object with `task` and `options` properties. The `options` can be a cron string, a one-shot Date/timestamp, `{ rule, tz?, start?, end? }`, or a node-schedule-style recurrence object. The task is called as `task({ strapi }, fireDate)`. ```javascript const { createCronService } = require('packages/core/strapi/lib/services/cron.js'); const cron = createCronService(); const task = () => { console.log('Task executed!'); }; cron.add({ myTask: { task, options: '*/5 * * * *', // Executes every 5 minutes. }, '*/1 * * * *': () => console.log('A minute has passed.'), }); ``` -------------------------------- ### Prop drilling example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/contributing/04-frontend-guidelines.md Shows prop drilling where state and setter are passed down to multiple components. This can become verbose and inconvenient. ```jsx import { useState } from 'react'; const App = () => { const [someState, setSomeState] = useState('some state'); return ( <>
); }; ``` -------------------------------- ### Start Strapi without autoReload (start) Source: https://github.com/strapi/strapi/blob/develop/examples/empty/README.md Starts the Strapi application with autoReload disabled. Use this for production or when you don't need automatic reloading. ```bash npm run start # or yarn start ``` -------------------------------- ### Create Strapi project with yarn Source: https://github.com/strapi/strapi/blob/develop/packages/core/strapi/README.md Quickstart command to create a new Strapi project using yarn. Generates a project with default features: authentication, permissions, content management, content type builder, and file upload. ```bash yarn create strapi ``` -------------------------------- ### Get all releases params Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/content-releases/01-backend.md Query parameters for the GET /content-releases/ endpoint. ```ts { page: number; pageSize: number; } ``` -------------------------------- ### Guided Tour State Type Definition Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/admin/guided-tour.md Defines the TypeScript type for the guided tour state, including the tours object, enabled flag, and completed actions. ```typescript type State = { tours: Tour; enabled: boolean; completedActions: ExtendedCompletedActions; }; ``` -------------------------------- ### Resolver function behavior with get Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/container.mdx Illustrates that the resolver function is called only on the first get, and subsequent gets return the cached value regardless of new args. ```javascript const container = new Container(); container.add('boolean', (bool) => bool); // First call - The value is resolved through the resolver above "(bool) => bool" container.get('boolean', true); // true // Any further call will use the previously set value container.get('boolean'); // true // Even if we try to push a new value container.get('boolean', false); // true ``` -------------------------------- ### Build, export, and format LikeC4 diagrams Source: https://github.com/strapi/strapi/blob/develop/architecture/README.md Run from the same directory as the dev server. Builds the project, exports PNG and Mermaid outputs, formats files, and runs the check command (which checks formatting). ```bash yarn build yarn export:png yarn export:mermaid yarn format yarn check ``` -------------------------------- ### Get all releases with/without an entry params Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/content-releases/01-backend.md Query parameters for the GET /content-releases/getByDocumentAttached endpoint. ```ts { contentTypeUid: string; locale?: string; documentId?: string; hasEntryAttached?: boolean; } ``` -------------------------------- ### Get a stored value with get Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/container.mdx Shows retrieving a value by name. If the resolver is a function, the value is the result of calling it with args on the first get; the result is not awaited, so promises are stored as promises. ```javascript const container = new Container(); container.add('config', { db: 'sqlite' }); const config = container.get('config'); // config.db === 'sqlite' ``` -------------------------------- ### Create a plugin Source: https://github.com/strapi/strapi/wiki/Switch-from-dev-app-to-prod Creates a dev app and generates a new plugin named my-plugin. After creation, copy the my-plugin folder into the repositories folder where Strapi is cloned. ```bash # In a terminal window $ cd sandbox && strapi new my-app --dev $ cd my-app && strapi generate:plugin my-plugin ``` -------------------------------- ### Quick reference migration test commands Source: https://github.com/strapi/strapi/blob/develop/tests/migration/README.md Quick reference commands for local migration testing: smoke test, plan-only, full run with sqlite, and scenario-based run. ```bash yarn test:migrations:smoke ``` ```bash yarn test:migrations:plan --initial legacy ``` ```bash yarn test:migrations --initial legacy --database sqlite --skip-build ``` ```bash yarn test:migrations --scenario tests/migration/scenarios/v4-to-head.json ``` -------------------------------- ### Run full migration test with sqlite Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Full migration flow after building, using sqlite database and skipping build if dist is current. Requires --initial flag with a 4.x semver version. ```bash yarn test:migrations --initial legacy --database sqlite --skip-build ``` -------------------------------- ### Build admin and plugins for prod Source: https://github.com/strapi/strapi/wiki/Switch-from-dev-app-to-prod Builds the admin and plugins in the Strapi repository to switch from a dev app to a prod app. Run after modifying the front-end. ```bash # In a terminal window navigate to the strapi repository $ cd repositories/strapi # Build the plugins with your modification $ npm run setup:build ``` -------------------------------- ### Start Transfer Step Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/data-transfer/02-providers/05-remote-strapi/01-websocket.md Signals the start of a transfer step (e.g., schemas, entities, assets, links, config). ```javascript dispatchTransferStep(action: "start", step) ``` -------------------------------- ### Install, run, build, scaffold, and type-check the docs site Source: https://github.com/strapi/strapi/blob/develop/docs/README.md Run these commands in the docs/ directory. yarn build fails on broken links and invalid frontmatter; yarn scaffold:packages creates missing package pages; yarn tsc --noEmit type-checks components and plugins. ```bash yarn install # install dependencies yarn start # dev server with live reload yarn build # production build; fails on broken links and invalid frontmatter yarn scaffold:packages # create the missing package pages yarn tsc --noEmit # type-check the components and plugins ``` -------------------------------- ### generate function example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/openapi/03-usage.md Example of calling generate with the content-api type to obtain the document and duration. ```typescript import { generate } from '@strapi/openapi'; const { document, durationMs } = generate(strapi, { type: 'content-api' }); ``` -------------------------------- ### Run migration smoke test Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Quick smoke test from the repository root, taking about 1-2 minutes on a warm tree. ```bash yarn test:migrations:smoke ``` -------------------------------- ### Get Sentry instance with getInstance Source: https://github.com/strapi/strapi/blob/develop/packages/plugins/sentry/README.md Get direct access to the initialized Sentry instance when sendError doesn't suit your needs. ```js const sentryInstance = strapi.plugin('sentry').service('sentry').getInstance(); ``` -------------------------------- ### Guided Tour TypeScript Types Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/admin/guided-tour.md Defines the core TypeScript types for the guided tour feature, including tour steps, state management, actions, metadata, step components, and the tour object. Use these types to understand the shape of tour configuration and state. ```typescript // Tour configuration type TourStep

= { name: P; content: Content; when?: (completedActions: ExtendedCompletedActions) => boolean; excludeFromStepCount?: boolean; // Exclude from "Step X of Y" counting }; // State management type State = { tours: Tour; enabled: boolean; completedActions: ExtendedCompletedActions; }; type Action = | { type: 'next_step'; payload: ValidTourName } | { type: 'skip_tour'; payload: ValidTourName } | { type: 'previous_step'; payload: ValidTourName } | { type: 'go_to_step'; payload: { tourName: ValidTourName; step: number } } | { type: 'set_completed_actions'; payload: ExtendedCompletedActions } | { type: 'skip_all_tours' } | { type: 'reset_all_tours' }; // Tour metadata type TourMeta = { totalStepCount: number; displayedStepCount: number; }; // Step components type Step = { Root: React.ForwardRefExoticComponent; Title: (props: StepProps) => React.ReactNode; Content: (props: StepProps) => React.ReactNode; Actions: (props: ActionsProps & { to?: string } & FlexProps) => React.ReactNode; }; // Tour object includes both steps and metadata type Tour = Components & { _meta: TourMeta }; ``` -------------------------------- ### Quick usage with package manager create commands Source: https://github.com/strapi/strapi/blob/develop/packages/cli/create-strapi/README.md Use the package manager's create command to scaffold a new Strapi project. The @latest tag ensures the most recent version is used. ```sh npm init strapi@latest yarn create strapi@latest pnpm create strapi@latest ``` -------------------------------- ### Fetch and wrap preview script with runtime config Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/content-manager/06-preview.md The admin fetches the preview script from the server endpoint, wraps it with runtime configuration (colors, events, parent origin), and posts it to the iframe. The script is served verbatim and must be self-contained; it cannot import dependencies or reference external variables. ```TypeScript const previewScriptSource = await fetch( `${window.strapi.backendURL}/content-manager/preview/script` ).then((res) => res.text()); const config = { colors: previewHighlightColors, events: INTERNAL_EVENTS, parentOrigin: window.location.origin, }; const script = `(${previewScriptSource})(${JSON.stringify(config)})`; ``` -------------------------------- ### Quick usage with npx Source: https://github.com/strapi/strapi/blob/develop/packages/cli/create-strapi-app/README.md Use this command to create a new Strapi project with the create-strapi-app CLI via npx. Replace 'my-project' with your desired project name. ```bash npx create-strapi-app my-project ``` -------------------------------- ### Configure strapi-views in custom.json Source: https://github.com/strapi/strapi/wiki/Migration-guide Add this configuration to ./config/environments/**/custom.json to enable the views hook. You may need to install the template engine yourself, e.g., npm install ejs --save. ```json { "views": { "enabled": true, "map": { "ejs": "ejs" }, "viewExt": "ejs", "debug": true, "cache": true } } ``` -------------------------------- ### Example jscodeshift code transform for Strapi upgrade Source: https://github.com/strapi/strapi/blob/develop/packages/utils/upgrade/README.md Uses the jscodeshift library to modify code. The `file` and `api` parameters come from jscodeshift. This example replaces all `console.log` calls with `console.info`. ```typescript import type { Transform } from 'jscodeshift'; const transform: Transform = (file, api) => { // Extract the jscodeshift API const { j } = api; // Parse the file content const root = j(file.source); root // Find console.log calls expressions .find(j.CallExpression, { callee: { object: { name: 'console' }, property: { name: 'log' } }, }) // For each call expression .forEach((path) => { const { callee } = path.node; if ( // Make sure the callee is a member expression (object/property) j.MemberExpression.check(callee) && // Make sure the property is an actual identifier (contains a name property) j.Identifier.check(callee.property) ) { // Update the property's identifier name callee.property.name = 'info'; } }); // Return the updated file content return root.toSource(); }; export default transform; ``` -------------------------------- ### container.get(name, args) Source: https://github.com/strapi/strapi/blob/develop/docs/docs/api/container.mdx Gets the value stored for a specific name. If the resolver is a function, the value will be the result of this resolver function with args as parameter on the first call to get. ```APIDOC ## container.get(name, args) ### Description Gets the value stored for a specific name. If the resolver is a function, the value will be the result of this resolver function with args as parameter on the first call to get. ### Parameters - **name** (String) - Required - UID of the content - **args** (Any) - Optional - Value that will be passed to the resolver (if function) ### Request Example ```javascript const container = new Container(); container.add('config', { db: 'sqlite' }); const config = container.get('config'); // config.db === 'sqlite' ``` ### Notes - If the resolver is a function, the value will be the result of this resolver function with args as parameter on the first call to get. - The resolver result value isn't awaited. So if resolver returns a promise, the value stored will be a promise. ### Request Example ```javascript const container = new Container(); container.add('boolean', (bool) => bool); // First call - The value is resolved through the resolver above "(bool) => bool" container.get('boolean', true); // true // Any further call will use the previously set value container.get('boolean'); // true // Even if we try to push a new value container.get('boolean', false); // true ``` ``` -------------------------------- ### Run @strapi/upgrade CLI commands Source: https://github.com/strapi/strapi/blob/develop/packages/utils/upgrade/README.md Run from a Strapi project directory. The first command shows help, the second upgrades to a specific version. Use `strapi upgrade` if Strapi is locally installed, or for monorepo development run the bin directly. ```bash npx @strapi/upgrade --help npx @strapi/upgrade to 5.42.0 ``` -------------------------------- ### GET /review-workflows/workflows Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/review-workflows/01-backend.md Returns a list of all workflows. ```APIDOC ## GET /review-workflows/workflows ### Description Returns a list of all workflows. ### Method GET ### Endpoint /review-workflows/workflows ``` -------------------------------- ### Run migration test with scenario file Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Runs migration test using a JSON scenario file instead of --initial flag. ```bash yarn test:migrations --scenario tests/migration/scenarios/v4-to-head.json ``` -------------------------------- ### Local documentation workflow commands Source: https://github.com/strapi/strapi/blob/develop/docs/docs/contributing/07-writing-docs.md Run these commands in the `docs/` directory. `yarn build` fails on broken links and invalid frontmatter; `yarn serve` serves the production build where redirects work. ```bash yarn install # once yarn start # dev server with live reload yarn build # production build; fails on broken links and invalid frontmatter yarn serve # serve the production build (redirects work here) yarn scaffold:packages # create the missing package pages yarn tsc --noEmit # type-check the components and plugins ``` -------------------------------- ### Quick usage with yarn create Source: https://github.com/strapi/strapi/blob/develop/packages/cli/create-strapi-app/README.md Use this command to create a new Strapi project with the create-strapi-app CLI via yarn create. Replace 'my-project' with your desired project name. ```bash yarn create strapi-app my-project ``` -------------------------------- ### usePersistentState usage example Source: https://github.com/strapi/strapi/blob/develop/docs/docs/packages/core/admin/hooks/use-persistent-state.md Stores data in local storage. The hook returns a stateful value and a setter, similar to useState, but persists the value under the given key. In this example, the state 'navbar-open' defaults to true and controls the visibility of a menu. ```js import { usePersistentState } from '@strapi/helper-plugin'; const MyComponent = () => { const [navbarOpened, setNavbarOpened] = usePersistentState('navbar-open', true); return

; }; ``` -------------------------------- ### Typical migration workflow - restore snapshot Source: https://github.com/strapi/strapi/blob/develop/examples/complex/README.md Step 10: Restore snapshot to reset database. ```bash yarn db:restore:postgres mybackup ```