Payload requires the following software:
To quickly scaffold a new Payload app in the fastest way possible, you can use create-payload-app. To do so, run the following command:
Then just follow the prompts! You'll get set up with a new folder and a functioning Payload app inside.
Adding Payload to either a new or existing TypeScript + Express app is super straightforward. To add to an existing app, just run
npm install --save --legacy-peer-deps payload.
From there, the first step is writing a baseline config. Create a new
payload.config.ts in your project's
/src directory (or whatever your root TS dir is). The simplest config contains the following:
Write the above code into your newly created config file. This baseline config will automatically provide you with a default
User collection. For more information about users and authentication, including how to provide your own user config, jump to the Authentication section.
Although this is just the bare minimum config, there are many more options that you can control here. To reference the full config and all of its options, click here.
Now that you've got a baseline Payload config, it's time to initialize Payload. It requires an Express server that you provide, so if you're not familiar with how to set up a baseline Express server, please read up on exactly what Express is and why to use it. Express' own Documentation is a good place to start. Otherwise, follow along below for how to build your own Express server to use with Payload.
npm install --save --legacy-peer-deps expressif you have not done so already
server.tsfile in the root directory of your app
This server doesn't do anything just yet. But, after you have this in place, we can initialize Payload via its asynchronous
init() method, which accepts a small set of arguments to tell it how to operate.
To initialize Payload, update your
server.ts file to reflect the following code:
Here is a list of all properties available to pass through
Required. This is your Express app as shown above. Payload will tie into your existing
app and scope all of its functionalities to sub-routers. By default, Payload will add an
/admin router and an
/api router, but you can customize these paths.
Required. This is a secure string that will be used to authenticate with Payload. It can be random but should be at least 14 characters and be very difficult to guess. Often, it's smart to store this value in an
env and set different values for each of your environments (local, stage, prod, etc). The
dotenv package is very handy and works well alongside of Payload.
Required. This is a fully qualified MongoDB connection string that points to your Mongo database. If you don't have Mongo installed locally, you can follow these steps for Mac OSX and these steps for Windows 10. If you want to use a local database and you know you have MongoDB installed locally, a typical connection string will look like this:
In contrast to running Mongo locally, a popular option is to sign up for a free MongoDB Atlas account, which is a fully hosted and cloud-based installation of Mongo that you don't need to ever worry about.
Customize Mongo connection options. Payload will connect to your MongoDB database using default options which you can override and extend to include all the options available to mongoose.
An object used to configure SMTP. Read more.
A boolean that when set to
true tells Payload to start in local-only mode which will bypass setting up API routes. When set to
express is not required. This is useful when running scripts that need to use Payload's local-api.
Specify options for the built-in Pino logger that Payload uses for internal logging. See Pino Docs for more info on what is available.
A function that is called immediately following startup that receives the Payload instance as it's only argument.
After you've gotten this far, it's time to boot up Payload. Start your project in your application's folder to get going.
After it starts, you can go to
http://localhost:3000/admin to create your first Payload user!
Looking to deploy Payload with Docker? New projects with
create-payload-app come with a Dockerfile and docker-compose.yml file ready to go. Examples of these files can be seen in our Deployment docs.