Skip to content

Installation

  • Node.js: Version 18.0 or higher
  • Strapi: Version 4.x or 5.x
  • Package Manager: npm, pnpm, yarn, or bun
Terminal window
npm install -D strapi2front

Run the init command to create a configuration file:

Terminal window
npx strapi2front init

This will create a strapi.config.ts file with sensible defaults.

strapi2front uses two separate tokens for different purposes:

Used by the CLI to fetch your schema during development. Create one in the Strapi admin panel:

  1. Go to Settings > API Tokens
  2. Click Create new API Token
  3. Give it a name like “strapi2front sync”
  4. Set the token type to Custom
  5. Configure the following permissions:

Required permissions:

PluginPermissionDescription
Content-type-buildergetComponentsRead component schemas
Content-type-buildergetComponentRead individual component
Content-type-buildergetContentTypesRead content type schemas
Content-type-buildergetContentTypeRead individual content type

Optional permissions (if using i18n):

PluginPermissionDescription
I18nlistLocalesRead available locales

Used by your generated client to fetch content at runtime. Create a separate token with only the permissions your app needs:

  1. Go to Settings > API Tokens
  2. Click Create new API Token
  3. Give it a name like “Frontend”
  4. Set the token type to Custom or Read-only (depending on your needs)
  5. Grant only the permissions your frontend needs (e.g., find and findOne for your content types)

Create a .env file in your project root:

Terminal window
STRAPI_URL=http://localhost:1337
# Sync token: Used by strapi2front to sync schema (development only)
# Permissions: content-type-builder, i18n
STRAPI_SYNC_TOKEN=your-sync-token-here
# Frontend token: Used by your app to fetch content (production)
# Configure with only the permissions your app needs
STRAPI_TOKEN=your-frontend-token-here

Then reference them in your config:

import { defineConfig } from "strapi2front";
export default defineConfig({
url: process.env.STRAPI_URL || "http://localhost:1337",
// Uses STRAPI_SYNC_TOKEN for sync, falls back to STRAPI_TOKEN
token: process.env.STRAPI_SYNC_TOKEN || process.env.STRAPI_TOKEN,
// ... rest of config
});

strapi2front supports both TypeScript and JavaScript projects:

import { defineConfig } from "strapi2front";
export default defineConfig({
outputFormat: "typescript", // .ts files with type annotations
// ...
});
import { defineConfig } from "strapi2front";
export default defineConfig({
outputFormat: "jsdoc", // .js files with JSDoc comments
// ...
});

Run the sync command to test your setup:

Terminal window
npx strapi2front sync

If successful, you’ll see output similar to:

◇ strapi2front sync
◇ Configuration loaded
◇ Strapi v5
◇ Schema fetched: 3 collections, 1 singles, 5 components
◇ Generated 18 files
┌─────────────────────────────────────────────────────────────┐
│ │
│ Generated 18 files in src/strapi │
│ │
│ Files generated: │
│ src/strapi/shared/utils.ts │
│ src/strapi/shared/client.ts │
│ src/strapi/shared/locales.ts │
│ src/strapi/collections/article/types.ts │
│ src/strapi/collections/article/schemas.ts │
│ src/strapi/collections/article/service.ts │
│ src/strapi/collections/article/actions.ts │
│ ... and 11 more │
│ │
└─────────────────────────────────────────────────────────────┘
└ Types, Services, Schemas, Actions ready to use!

Make sure your Strapi server is running and the URL is correct.

Your API token may be invalid or expired. Generate a new one in Strapi admin.

Run npx strapi2front init to create the configuration file.