nextstarter for Next.js 14
This guide will walk you through setting up nextstarter for Next.js (with app router). We will go through the process of installing dependencies, setting up your database and running the local development server.
Tools & libraries
Before we start I quickly want to go over the tools and libraries that nextstarter uses.
- 🚀 TurboRepo (opens in a new tab) -> Monorepo
- 👨🏼💻 Next.js 14 with app router (opens in a new tab) -> React framework
- 💽 Prisma (opens in a new tab) -> ORM (Database access layer)
- 🔐 Lucia Auth (opens in a new tab) -> Authentication
- 💅🏼 Tailwind CSS (opens in a new tab) -> CSS framework
- 🧩 Radix UI (opens in a new tab) -> Headless components
- 📝 content-collections (opens in a new tab) -> MDX based CMS
- 💳 Stripe (opens in a new tab) or Lemonsqueezy (opens in a new tab) -> Payment processing
- 📫 React Email (opens in a new tab) -> Email templates in React
Prerequisites
Before you can get started, you will need to have the following installed on your machine.
- Node.js (opens in a new tab) (v20 or higher)
- Git (opens in a new tab)
- pnpm (opens in a new tab)
- VSCode (opens in a new tab) (recommended, or any other code editor)
Project setup
Create a new database
nextstarter uses Prisma (opens in a new tab) as an ORM (database access layer). This means you can use any database supported by Prisma, including PostgreSQL, MySQL, SQLite, and MongoDB. You can find all supported databases here (opens in a new tab).
Before creating a new nextstarter project, make sure to have created a new database and have the connection string ready. For example when using PostgreSQL, the connection string will look something like this:
postgresql://user:password@host:port/database
Recommended database providers are Supabase (opens in a new tab), PlanetScale (opens in a new tab) and Neon (opens in a new tab).
Initialize a new nextstarter project
During the setup process you will be asked to provide the following information:
- Project name - The name of your project
- Database provider - The database provider you are using
- Database connection string - The connection string of your database
First, we are going to install all the dependencies. Make sure you have installed pnpm (opens in a new tab) before running the following command:
pnpm install
Now, we need to set up the environment variables. To do this, copy the .env.local.example file in the root of your project and rename it to .env.local.
Then open the .env.local file and set at least the DATABASE_URL
:
# Database
DATABASE_URL="YOUR_DATABASE_CONNECTION_STRING"
This is also the place to set the variables for your mailing provider.
Here are the necessary variables for each provider:
- Plunk ->
PLUNK_API_KEY
- Resend ->
RESEND_API_KEY
- Postmark ->
POSTMARK_SERVER_TOKEN
- Nodemailer ->
MAIL_HOST
,MAIL_PORT
,MAIL_USER
,MAIL_PASS
Next, we need to link the correct providers for payments and mailing.
In the /packages/mail/providers/index.ts
file, set the export to the provider you want to use:
export from './plunk';
// or export * from './resend';
// or export * from './postmark';
// or export * from './nodemailer';
Do the same for the payment provider in the packages/api/modules/billing/provider/index.ts
file:
export * from './stripe';
// or export * from './lemonsqueezy';
Next step is to migrate your database. Make sure to check your schema in packages/database/prisma/schema.prisma
before.
To migrate the database, run the following command:
pnpm db:push
Then, to generate the Prisma client, run the following command:
pnpm db:generate
Set up your storage provider
Storage is necessary to upload and serve files like images for example for the avatars of users and teams. nextstarter supports multiple storage providers, so please ollow the instructions for your preferred provider:
Start your development server
Now your app should be ready to go. To start the local development server, navigate into your project root folder and run the following command.
pnpm dev
Open http://localhost:3000 (opens in a new tab) (opens in a new tab) in your browser to see the your app.