A simple todo app built on Next.js and Tigris using TypeScript client, deployed on Netlify.
You can see the demo live at https://tigris-todo-starter.netlify.app/
You have two options to run this Next.js app:
- A GitHub account. Sign up here for a free account if you don't have one.
- A Netlify account for deploying app. Sign up here for a free account if you don't have one.
- A Tigris account. Sign up here for a free account if you don't have one.
- Login to Tigris console and follow the video instruction
to register a new application under
My Settings > Application Keys
. In the next step, we will use the generatedClient ID
andClient Secret
as Environment Variables when deploying our Next.js app on Netlify. - Hit "Deploy" and follow instructions to fork this repo and deploy app to your Netlify account
🎉 All done. You should be able to use app on the URL provided by Netlify. Feel free to play around or do a code walkthrough next 🎉
Running Next.js server & Tigris dev environment on your local computer
- Tigris installed on your dev computer
- For macOS:
brew install tigrisdata/tigris/tigris-cli
- Other operating systems: See installation instructions here
- For macOS:
- Node.js version 16+
- Clone this repo on your computer
git clone https://github.com/tigrisdata/tigris-netlify-starter
- Install dependencies
cd tigris-netlify-starter
npm install
- Add the environment variables into a file
.env.development.local
TIGRIS_URI="api.preview.tigrisdata.cloud"
TIGRIS_CLIENT_ID="your client id"
TIGRIS_CLIENT_SECRET="your client secret"
- Run the Next.js server
npm run dev
Note: This step will also initialize Tigris database and collection for app.
🎉 All done. You should be able to use app on localhost:3000
in browser. Feel free to play
around or do a code walkthrough next 🎉
📂 File structure
├── package.json
├── models
│ └── tigris
│ └── tigris_netlify_starter
│ └── todoItems.ts
├── lib
│ ├── tigris.ts
└── pages
├── index.tsx
└── api
├── item
│ ├── [id].ts
└── items
├── index.ts
└── search.ts
The to-do list app has a single collection todoItems
defined in models/tigris/tigris_netlify_starter/todoItems.ts
that stores the to-do items in todoStarterApp
database. The
Database and Collection get automatically provisioned by the setup script.
This is an inspiration from Next.js based file system router. Create a folder or drop a schema file
inside database folder under models/tigris/
, and you're able to instantly create Databases and
Collections in Tigris for your application.
The lib/tigris.ts file loads the environment variables you
specified previously in creating a Netlify project
section and uses them to configure the Tigris client. Locally, you will want
to make sure to create a .env.development.local
file to store your environment variables. With Netlify, make sure to add them either on the site or through the CLI.
❇️ API routes to access data in Tigris collection
All the Next.js API routes are defined under pages/api/
. We have three files exposing endpoints:
GET /api/items
to get an array of to-do items as ArrayPOST /api/items
to add an item to the list
GET /api/items/search?q=query
to find and return items matching the given query
GET /api/item/{id}
to fetch an itemPUT /api/item/{id}
to update the given itemDELETE /api/item/[id]
to delete an item
In a few steps, we learnt how to bootstrap a Next.js app using Tigris and deploy it on Netlify. Feel free to add more functionalities or customize App for your use-case and learn more about Tigris data platform.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue. Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request