

Welcome to the first part of our tutorial series on Payload NextJS! In this guide, we will walk you through the essential steps to set up Payload CMS effectively, ensuring you have a solid foundation for your project. From initializing your MongoDB Atlas project to deploying on Railway, we've got you covered.
This is the written guide for our Comprehensive Payload NextJS Setup Guide Series (Part 1). You can find the full length video here:
https://www.youtube.com/watch?v=jCxmA4usUAw
Payload CMS is a headless content management system that allows developers to create and manage content seamlessly. It stands out due to its flexibility and developer-friendly features. With Payload, you can build custom content structures, use modern frameworks like NextJS, and manage your content through a powerful admin interface.
What makes Payload unique is its focus on developer experience. It uses a schema-based approach, allowing you to define content types with rich fields and relationships. This means you can create complex data structures that fit your application's needs without compromise.
Choosing Payload CMS offers numerous benefits:
To kick off your Payload project, the first step is to set up a MongoDB Atlas account. This cloud database service offers a free tier, which is perfect for small projects. Here’s how to get started:
Once these configurations are complete, you’ll have a MongoDB Atlas cluster ready to use.

Now that you have your MongoDB Atlas cluster set up, it’s time to initialize your Payload project. This is done using the command line interface.
npx create-payload-app your-project-name. This command creates a boilerplate Payload project.cd your-project-name.npm run dev.This will launch your Payload CMS application, and you can access it via your browser.

Configuring environment variables is crucial for your application to communicate with MongoDB Atlas securely. Here’s how to set them up:
.env.MONGODB_URI=mongodb+srv://:@cluster.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
.gitignore.These variables will help Payload connect to your database securely, ensuring your credentials are not exposed.
To optimize your Payload application, you need to adjust both the Payload and Webpack configurations. This ensures that your application runs smoothly and avoids common pitfalls.
Open the payload.config.ts file in your project. Here are some adjustments to consider:
Next, modify your Webpack configuration. This is particularly important for handling server-only modules:
These adjustments will improve the performance and security of your Payload CMS application.
By default, Payload saves uploaded files to the local hard drive, which isn’t ideal for multi-environment setups. Instead, using S3 storage is a better approach. Here’s how to set it up:
npm install aws-sdk multer-s3
This setup ensures that your uploaded files are stored externally, making it easier to manage across different environments.
Once your Payload NextJS project is up and running, setting up a transactional email service is essential for effective communication. For testing purposes, Payload offers a service called Ethereal Email. However, this can be cumbersome since it generates new credentials every time the server restarts.
To streamline this process, we will implement a workaround. For production emails, we will use Brevo, formerly known as Sendinblue. Brevo is a GDPR-compliant email service, making it a solid choice for European projects.
npm install nodemailer
3. Configure your email settings in the payload.config.ts file, like so:
import nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
host: 'smtp.brevo.com',
port: 587,
auth: {
user: '',
pass: '',
},
}); 4. Define your email templates and send emails using the transporter you configured.
This setup allows you to send transactional emails seamlessly, enhancing user experience.
To enhance the aesthetics of your admin panel, integrating Tailwind CSS is a game-changer. Tailwind allows for rapid styling with utility-first classes, making it easy to customize without losing the default styles of Payload.
npm install tailwindcss postcss autoprefixer
npx tailwindcss init -p
tailwind.config.js, specify the paths to your template files:module.exports = {
content: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
theme: {
extend: {},
},
plugins: [],
};@tailwind base;
@tailwind components;@tailwind utilities;
Now Tailwind CSS is ready to use, allowing you to customize the admin panel effortlessly.
Deploying your Payload NextJS project can be a daunting task, but Railway simplifies the process significantly. With Railway, you can connect your GitHub repository and deploy your project quickly without the hassle of managing servers.
Once deployed, Railway automatically redeploys your project every time you push changes to your GitHub repository, making it incredibly efficient.
One of the standout features of Railway is its cost efficiency. Unlike traditional servers where you pay a flat rate, Railway only charges for the resources you use. This is particularly beneficial for small to medium-sized projects.
This pricing model ensures that you can scale your project without the fear of skyrocketing costs.
Congratulations! You’ve successfully set up your Payload NextJS project with essential functionalities like transactional emails and Tailwind CSS integration. The deployment on Railway further streamlines your workflow.
As you move forward, consider exploring advanced features of Payload CMS. Integrate more complex content types or enhance your admin panel with custom functionality. The possibilities are endless!
Payload NextJS is a headless content management system that seamlessly integrates with NextJS, allowing for flexible content management and a robust developer experience.
You can easily set up a MongoDB Atlas database, which is free for small projects. Follow the configuration steps outlined earlier to connect Payload to your database.
Yes, while we recommend Brevo for its GDPR compliance, you can integrate other email services like SendGrid or Mailgun as well.
No, you can deploy your Payload NextJS project on various platforms, but Railway simplifies the process significantly.