Giter VIP home page Giter VIP logo

nextjs-starter's Introduction

Next.js starter

This is a Next.js project that uses Prisma to connect to a PlanetScale database and Tailwind CSS for styling.

Prerequisites

pscale auth login

Set up the database

Create a new database with the following command:

pscale database create <DATABASE_NAME>

A branch, main, was automatically created when you created your database, so you can use that for BRANCH_NAME in the steps below.

Set up the starter Next.js app

Clone the starter repository.

git clone https://github.com/planetscale/nextjs-starter

Install the dependencies.

npm install

Next, you'll need to create a database username and password through the CLI to connect to your application. If you'd prefer to use the dashboard for this step, you can find those instructions in the Connection Strings documentation and then come back here to finish setup.

First, create your .env file by renaming the .env.example file to .env:

mv .env.example .env

Next, using the PlanetScale CLI, create a new username and password for the branch of your database:

pscale password create <DATABASE_NAME> <BRANCH_NAME> <PASSWORD_NAME>

The PASSWORD_NAME value represents the name of the username and password being generated. You can have multiple credentials for a branch, so this gives you a way to categorize them. To manage your passwords in the dashboard, go to your database overview page, click "Settings", and then click "Passwords".

Take note of the values returned to you, as you won't be able to see this password again.

Password production-password was successfully created.
Please save the values below as they will not be shown again

  NAME                  USERNAME       ACCESS HOST URL                     ROLE               PLAIN TEXT
 --------------------- -------------- ----------------------------------- ------------------ -------------------------------------------------------
  production-password   xxxxxxxxxxxxx   xxxxxx.us-east-2.psdb.cloud   Can Read & Write   pscale_pw_xxxxxxx                                                                                    

You'll use these properties to construct your connection string, which will be the value for DATABASE_URL in your .env file. Update the DATABASE_URL property with your connection string in the following format:

mysql://<USERNAME>:<PLAIN_TEXT_PASSWORD>@<ACCESS_HOST_URL>/<DATABASE_NAME>?sslaccept=strict

Push the database schema to your PlanetScale database using Prisma.

npx prisma db push

Run the seed script to populate your database with Product and Category data.

npx run seed

Run the App

Run the app with following command:

npm run dev

Open your browser at localhost:3000 to see the running application.

Deploying

After you've got your application running locally, it's time to deploy it. To do so, you'll need to promote your database branch (main by default) to be the production branch (read the branching documentation for more information).

pscale branch promote <DATABASE_NAME> <BRANCH_NAME>

Now that your branch has been promoted to production, you can either use the existing password you generated earlier for running locally or create a new password. Regardless, you'll need a password in the deployment steps below.

Choose one of the following deploy buttons and make sure to update the DATABASE_URL variable during this setup process.

Deploy on Vercel

Deploy with Vercel

Deploy on Netlify

*Note: The Netlify.toml file in this repository includes the configuration for you to customize the DATABASE_URL property on the initial deploy.

Deploy to Netlify

Learn More

To learn more about PlanetScale, take a look at the following resources:

What's next?

Learn more about how PlanetScale allows you to make non-blocking schema changes to your database tables without locking or causing downtime for production databases. If you're interested in learning how to secure your application when connecting to PlanetScale, please read Connecting to PlanetScale securely.

Need help?

Get help from PlanetScale's support team, or join our GitHub Discussion board to see how others are using PlanetScale.

nextjs-starter's People

Contributors

jamesqquick avatar skottler avatar nickvanw avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.