Payload CMS

3.83.0 · active · verified Tue Apr 21

Payload is an open-source, TypeScript-first headless CMS and application framework built on Node.js and React, frequently integrated with Next.js for full-stack applications. It is currently at version 3.83.0 and maintains an active release cadence, with multiple minor versions and bug fixes published monthly, indicating continuous and rapid development. A key differentiator is its code-first configuration approach, allowing developers to define collections, globals, and other configurations programmatically using TypeScript. This facilitates strong version control, type safety, and a developer-centric workflow, distinguishing it from CMS platforms that primarily rely on UI-driven configuration. Payload also provides a robust GraphQL API out-of-the-box, flexible authentication mechanisms, and a customizable, self-hosted admin panel, making it suitable for both content management and complex application backends.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a minimal Payload configuration with two collections (Users and Posts), including authentication, basic fields, and relationship fields. It shows the `buildConfig` utility and how to define schemas. It also outlines the typical server initialization process.

import { buildConfig } from 'payload/config';
import path from 'path';

const Users = {
  slug: 'users',
  auth: true,
  admin: {
    use=>: 'Email',
  },
  fields: [
    {
      name: 'name',
      type: 'text',
    },
  ],
};

export default buildConfig({
  serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL ?? 'http://localhost:3000',
  admin: {
    user: 'users',
  },
  collections: [
    Users,
    {
      slug: 'posts',
      fields: [
        {
          name: 'title',
          type: 'text',
          required: true,
        },
        {
          name: 'content',
          type: 'richText',
        },
        {
          name: 'author',
          type: 'relationship',
          relationTo: 'users',
        },
      ],
    },
  ],
  typescript: {
    outputFile: path.resolve(__dirname, 'payload-types.ts'),
  },
  graphQL: {
    schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
  },
});

// To run this, you would typically have a server entry point like:
// import payload from 'payload';
// import express from 'express';
// import { connect } from 'mongoose'; // or '@payloadcms/db-postgres'

// const app = express();

// async function start() {
//   await connect(process.env.MONGODB_URI ?? 'mongodb://localhost/payload');

//   await payload.init({
//     secret: process.env.PAYLOAD_SECRET ?? 'super-secret-default-key',
//     express: app,
//     onInit: () => {
//       payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
//     },
//   });

//   app.listen(3000, async () => {
//     payload.logger.info('Express is listening on port 3000');
//   });
// }

// start();

view raw JSON →