Skip to main content
This guide will get you from zero to generating types and services from your Strapi CMS in minutes.

Prerequisites

Before you begin, make sure you have:
  • Node.js 18+ installed on your machine
  • A Strapi v4 or v5 instance running (local or remote)
  • An API token from your Strapi admin panel

Installation

1

Install Strapi2Front

Install the CLI as a dev dependency in your project:
npm install -D strapi2front
2

Initialize Configuration

Run the init command to create a configuration file:
npx strapi2front init
This creates a strapi.config.ts file in your project root with sensible defaults.
3

Configure Your Connection

Update the generated config file with your Strapi URL and token:
strapi.config.ts
import { defineConfig } from "strapi2front";

export default defineConfig({
  // Your Strapi instance URL
  url: process.env.STRAPI_URL || "http://localhost:1337",
  
  // Your API token (create one in Strapi Admin > Settings > API Tokens)
  token: process.env.STRAPI_TOKEN,

  // Output directory
  output: {
    path: "src/strapi",
  },

  // Features to generate
  features: {
    types: true,      // TypeScript interfaces
    services: true,   // API service functions
    schemas: true,    // Zod validation schemas
    actions: true,    // Astro Actions (if using Astro)
    upload: false,    // File upload helpers
  },
});
Store your API token in a .env file and never commit it to version control:
.env
STRAPI_URL=http://localhost:1337
STRAPI_TOKEN=your-token-here
4

Generate Code

Run the sync command to fetch your Strapi schema and generate code:
npx strapi2front sync
You should see output like:
◇  strapi2front sync

◇  Configuration loaded

◇  Strapi v5

◇  Schema fetched: 3 collections, 1 singles, 5 components

◇  Generated 18 files

└  Types, Services, Schemas, Actions ready to use!

Using Generated Code

Once generation completes, you can import and use the generated types and services:
import { articleService } from "@/strapi/collections/article/service";

// Fetch all articles with pagination
const { data: articles, pagination } = await articleService.findMany({
  pagination: { page: 1, pageSize: 10 },
});

// Fetch a single article by documentId
const article = await articleService.findOne("abc123xyz");

// Fetch with filters
const { data: published } = await articleService.findMany({
  filters: { publishedAt: { $notNull: true } },
  sort: ["publishedAt:desc"],
});

Add to Your Workflow

Add a script to your package.json to regenerate code when your Strapi schema changes:
package.json
{
  "scripts": {
    "strapi:sync": "strapi2front sync",
    "dev": "strapi2front sync && vite"
  }
}

Next Steps