Skip to main content

Installation

This guide covers everything you need to install and configure Strapi2Front in your project.

System Requirements

Node.js

Version 18.0.0 or higher required

Strapi

Strapi v4 or v5 instance (local or remote)

Package Manager

npm, pnpm, yarn, or bun

TypeScript (Optional)

Works with both TypeScript and JavaScript projects

Installation Methods

The easiest way to get started is using the interactive init command:
This will:
  1. Detect your project configuration (framework, TypeScript, package manager)
  2. Prompt for Strapi connection details (URL, token, version)
  3. Create configuration file (strapi.config.ts or strapi.config.js)
  4. Set up environment variables (.env and .env.example)
  5. Install dependencies (optional)
The init command is safe to re-run. It won’t overwrite existing environment variables.

Manual Installation

If you prefer manual setup:
1

Install the package

Add Strapi2Front as a dev dependency:
  • strapi2front is a dev dependency (used for code generation)
  • @strapi/client is a runtime dependency (used by generated code)
2

Create configuration file

Create strapi.config.ts (or .js for JavaScript projects):
strapi.config.ts
3

Set up environment variables

Create or update your .env file:
.env
Create .env.example for your repository:
.env.example
Add .env to your .gitignore to avoid committing sensitive tokens:
.gitignore

Strapi API Token Setup

Strapi2Front requires an API token with specific permissions to read your content type schema.
1

Create API Token in Strapi

Navigate to your Strapi admin panel:Settings > API Tokens > Create new API Token
2

Configure Token Settings

  • Token name: strapi2front-sync
  • Token type: Custom
  • Token duration: Unlimited (for development)
Permissions:
  • Content-type-builder
    • Components: getComponents, getComponent
    • Content-types: getContentTypes, getContentType
  • I18n (if using localization)
    • Locales: listLocales
3

Save and Copy Token

Click Save and copy the generated token immediately.
Strapi only shows the token once. If you lose it, you’ll need to create a new one.
Add it to your .env file:
Why two tokens?
  • STRAPI_SYNC_TOKEN: Used by the CLI to read your schema (development only, should NOT be deployed)
  • STRAPI_TOKEN: Used by your app to fetch content (production, with limited read-only permissions)
The CLI will use STRAPI_SYNC_TOKEN if available, otherwise falls back to STRAPI_TOKEN.

File Upload Token (Optional)

If you enable the upload feature, you’ll need an additional token for file uploads:
1

Create Upload Token

In Strapi admin: Settings > API Tokens > Create new API Token
  • Token name: upload-token
  • Token type: Custom
  • Duration: As needed
  • Permissions:
    • Upload
      • upload (only)
    • ❌ No delete or update permissions (security best practice)
2

Add to Environment

Add both the URL and token:
.env
The PUBLIC_ prefix makes these variables available in client-side code (framework-specific naming may vary).

Verify Installation

Run the sync command to verify everything is set up correctly:
You should see output like:
If you encounter any errors, check the CLI Reference for troubleshooting common issues.

Framework-Specific Setup

Astro

1

Install Astro dependencies

2

Enable server output

If using Astro Actions, ensure your astro.config.mjs has:
astro.config.mjs
3

Configure environment variables

Astro uses PUBLIC_ prefix for client-side variables:
.env

Next.js

1

Configure environment variables

Next.js uses NEXT_PUBLIC_ prefix for client-side variables:
.env.local
2

Update strapi.config.ts

Point output to your src/lib directory:
strapi.config.ts

Nuxt

1

Configure environment variables

Nuxt uses NUXT_PUBLIC_ prefix:
.env

SvelteKit

1

Configure environment variables

SvelteKit uses PUBLIC_ prefix:
.env

NPM Scripts (Optional)

Add convenient scripts to your package.json:
package.json
Now you can use:

CI/CD Integration

To sync types in your CI/CD pipeline:

Next Steps

Quick Start

Get started with your first query

Configuration

Explore all configuration options

CLI Reference

Learn all available commands

Guides

Learn about types, services, and schemas