An example application demonstrating the basics of using Xata within a Next.js app using App Routing.
Install the Xata CLI:
npm install -g @xata.io/cliLogin to your Xata account or signup for an account and authenticate the Xata CLI:
xata auth loginnpx degit xataio/examples/apps/getting-started-nextjs xata-nextjsAnd cd into the app directory:
cd xata-nextjsInstall the dependencies:
npm installInitialize a new Xata project with the following command, agreeing to the default prompt options.
This step will create a new database with the name getting-started-nextjs for you, the .xatarc file and generate the type under src/xata.ts.
xata initThe above command will create a .env file containing your Xata project configuration.
| Key | Description |
|---|---|
XATA_API_KEY |
The API key to your Xata workspace. |
XATA_BRANCH |
The database branch to be used. |
Download a CSV file providing a basic schema and seed data for the application:
curl https://raw.githubusercontent.com/xataio/examples/main/seed/blog-posts.csv --create-dirs -o seed/blog-posts.csvCreate your database schema and seed the database using the CSV of blog post listings in seed/blog-posts.csv:
xata import csv seed/blog-posts.csv --table Posts --createNext, update the generated code in src/xata.ts based on the schema that was created by the above command:
xata pull mainRun the application as follows:
npm run devTo learn more about Xata and Next.js, take a look at the following resources: