Check out a free preview of the full Client-Side GraphQL with React, v2 course

The "Course Setup" Lesson is part of the full, Client-Side GraphQL with React, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Scott provides a setup guide and explains the tools and dependencies needed, such as Git, Node.js, and Turso. He walks through the process of creating a Turso account, downloading the CLI, and creating a token for the database. He also explains how to set up environment variables and push the schema to the database.

Preview
Close

Transcript from the "Course Setup" Lesson

[00:00:00]
>> Scott Moss: Setup, so here's everything you're gonna need. I promise you it's not crazy, you probably already have all of this other than this one thing here. So obviously, Git, you need Git. Go to the repo, I highly recommend forking it and then just pulling it down. So here's the link to the repo, you can just click on it if you didn't get it earlier, so go there and get that.

[00:00:18]
Node.js v20, at least version 20. It might work with version 18, I just haven't tested it so I can't guarantee it. I'm on version 20 and it works on my machine, [LAUGH] classic engineer thing. But yeah, I highly recommend v20 or later. You could try 18, if someone has 18 and wants to try it and let me know, cool.

[00:00:39]
But I'm using version 20. Once you have the repo fork and pull it down, if you didn't know already, always do an NPM install. I'm using NPM, so there's a package lock in there. I'm not using Yarn, I'm not using Bun, I'm using NPM. So highly recommend doing the NPM install if you want the same versions of everything that I installed.

[00:00:57]
If you do any one of those other package managers, you might not get the same versions. So depending on when you take this course later on the versions might be mismatched, so highly recommend just doing an NPM install here. And then this last one is going to be for the database that the backend is using.

[00:01:16]
So I tried to make this as simple as possible, because depending on what machine you're on you might have to download a database and downloading databases can be different and all that. So we're gonna use a database called Turso. Who here has heard of Turso DB? Never heard of Turso?

[00:01:33]
Well you're gonna be in for treat, cuz it's actually pretty cool. It's SQLite for production, it's actually a fork of SQLite, something called libSQL. If you don't know what SQLite is, it's like SQL but light. [LAUGH] It's file-based, so it's very portable, you can kinda bring it everywhere, it works on the edge.

[00:01:52]
It's kinda genius being able to use SQLite in production. So Turso is like a hosted version of that. So this database is completely hosted, you don't have to download anything other than a CLI and you can make an account for free. So if you go back to the notes, I kinda walk you through how to do that.

[00:02:09]
So go to the Turso, create an account. Follow the instructions to make a new database, I'm gonna do this right now. And then we're gonna download the CLI, we're gonna do some stuff, it should take a couple seconds, so let's go do that. So I'm going to Turso, all right, cool, so I already have an account so I'm just gonna log in.

[00:02:26]
And then I already have some databases. But once you log in, it'll walk you through setup where you need to create a database. If you read the instructions that I say there, it'll ask you create a replica. You don't need to create a replica, that's for production, just make the database.

[00:02:43]
Eventually you'll land on this screen that you see here. Once you get to this screen, you can just click on the Quickstart and it'll walk you through everything you need to do on your terminal to get started, which basically this involves downloading the CLI. So we could do that, we'll go here,

[00:03:03]
>> Scott Moss: And they have all the instructions. So Mac, Linux, Windows, click your appropriate operating system and copy the command to install the CLI. So once you have that installed they tell you to do a sign up, Turso all sign up, but you already just signed up, so you don't actually need to do that.

[00:03:27]
>> Scott Moss: You can just say Turso auth log in, and it'll open up the browser and ask you to log into your Turso account. So I'm gonna do it, but I think I'm already logged in, so yeah, it'll just say cool. So once you have that, we can follow the instructions about creating, or you should already have created a database in the Turso dashboard.

[00:03:52]
But we can follow these instructions here with this command to create a token for in your database, you need a token to be able to connect to it so you need to be able to do that. So what you can do is you can say turso db tokens create, and then the name of the database that you created on the Turso dashboard.

[00:04:15]
My database is called parallel. Your database name might be something different, whatever you called it when you created it.
>> Scott Moss: I'm not gonna hit Enter, cuz then it's gonna show my tokens. But if you do this, it'll create tokens for you. Or it'll create one token for you, it'll be a JSON web token.

[00:04:39]
So just remember that, don't clear your console, just keep it there, you're gonna use that in a second.
>> Scott Moss: And then what you're gonna do is you're gonna go into the repo, make a .env file.
>> Scott Moss: And you're going to add in that token as the Turso off token, and then the URL to your database in the .env file.

[00:05:14]
And if you don't know what these environment variables are, they're in the course notes, you can look at them from there, you can copy and paste them from there. If you don't know your connection URL you can use the Turso CLI, I'll show you how to do it but it basically it's just this URL.

[00:05:26]
It's libSQL, the name of your database, dash your username, dot turso.io. But if you don't wanna hard code that, you can actually just go into the Turso CLI here and do Turso DB list and it'll list all your databases with their URLs. It's connected, everything's good to go, now we just need to push our schema to it.

[00:05:49]
So we need to run the first initial migration, which is super simple, it's why I chose this database, so we'll do that in a second. But as far as setting the database up, it's done, you have it, it's there, it's deployed, it'll always work as long as you're connected to the Internet.

[00:06:04]
There is an option to do a local version, doing a local SQLite, but I kinda opted out of it. I was like, eh, it was just an extra step beyond what we just did so I was like, nah, maybe we won't do that. But you can run it locally if you want with a local SQLite.

[00:06:25]
>> Scott Moss: So the last thing here to get this database running is there is a command that I have in a package.json that's called db:push. So you can just do npm run db:push, and what that's gonna do, it's going to push up the schema that I created to your database.

[00:06:42]
But don't do this until you have set these variables in your .env file, it's relying on those, so make sure. And then also you should have did your NPM install to install your modules.
>> Scott Moss: So I'm gonna do this, I think it's going to destroy what I have cuz I already have kinda everything up there.

[00:07:06]
So I'm just going to say yes. It might have dropped my database, I'm not sure, but. Once you do that you are good to go, never gotta touch a database thing for the rest of this course, that's it. So we had some people in person have some trouble installing the Turso CLI on their machine.

[00:07:24]
So I'm gonna show you a workaround if that is the case, because the Turso CLI is not needed to start a database, the database is hosted already. We use the CLI to generate the tokens mostly, but you can actually do it from the dashboard. So if you go to Turso dashboard and you click on the database that you created, in this case here's my database.

[00:07:47]
You can see there's the URL, so that's the one environment variable. And then there's a button here that says generate token that you can generate the token, and that's the other environment variable. And that's it, so you don't need the CLI, you can just grab them here from the dashboard if you want and put those in your .env file.

[00:08:03]
And then run that db push command, which has nothing to do with Turso, it uses Drizzle which is our ORM, and that will push the schema to Turso. And then we're good to go, never have to touch a database again for the rest of this course.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now