Check out a free preview of the full Server-Side GraphQL in Next.js course

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

Scott provides instructions on how to set up the development environment for the course. He explains how to fork the repository, install the necessary dependencies using npm, and create a Turso account for the hosted SQLite database. He also guides students through creating a .env file to store secret variables and pushing the database schema to the Turso database.

Preview
Close

Transcript from the "Course Setup" Lesson

[00:00:00]
>> Speaker 1: Now as far as setup goes, fork the repo, pull it down. Once you have it, also make sure you have at least Node version 20. I built this on 20. I think this works with 18, just can't confirm. If somebody's using 18, please give it a try, let me know.

[00:00:16]
This should also work, if you prefer bun, this should work in the latest version of bun too. I actually prefer bun over note, I use it for everything. I tested it with bun, it does work, but I'm gonna use NPM here since that's just more widely accepted. And I highly recommend you also use NPM as far as installing the modules.

[00:00:34]
And that's because I have a package lock in the root to resolve all the dependency versions. So to make sure that this course continues to work into the future and doesn't download breaking change in modules, you should use NPM to install. If you use bun or yarn, it's gonna create a different lock for those installers and which will have different versions, which then you won't have the same version of what I have at the time of what I taught the course.

[00:00:57]
And I can't guarantee that things will work. So highly recommend using NPM to install. As far as the database goes, we're gonna be using something called Turso. If you've never heard of Turso, it is a hosted SQL lite database. So we don't have to install any database or run any database on our machine, it's all taken care of for us.

[00:01:17]
All we have to do is go create a free Turso account. I decided to use Turso because it's quite simple to get started. It's free, you can make as many databases as you will. I think you get 500 on a free plan, which is more than enough you need for this course.

[00:01:33]
And for the tooling that I use, which is like drizzle, there's great support. It's super fast. So it's just a good alternative. In the past, I've used different databases that I thought were really good and I use them in production, but then they'll go and knock off the free, yes, Mark?

[00:01:50]
If we have the DB setup from the client side Graph QL course, do we need a fresh one? Great question. So if you've taken a client side Graph QL course, you don't need to do anything here. You can use the same database. The only thing you would have to, and I'll get to that in a second, the specific thing you would have to do, but yeah, you don't have to set up a database right now.

[00:02:09]
If you've already have a Turso account, whether it's from the client side course, or you just already have a Turso account and you already have all that, you don't need to go make an account. But if you don't have an account, please go make an account. It's free, you can sign up, takes two seconds.

[00:02:22]
Once you do that, on the Turso dashboard, I'm gonna go there right quick. So I'm going to my dashboard. Eventually, once you sign up, you'll land here on the dashboard. And if you go and click on Databases, you can find your database. Mine is called Parallel. And then here you'll see a URL.

[00:02:42]
So take note of this, you're gonna need this URL. And then if you click this button, Generate Token, make sure it's read, right? Click Generate Token, that's gonna generate a JSON web token for you so you can authenticate with your database. Keep note of that, you're gonna need those two for the next step And then for the next step, you need to create a .env file on the root of your fold or the root of your repo.

[00:03:12]
If you don't know what that is, a .env file is a file that doesn't get checked into GitHub. It's where you can store secret variables into your application that can be changed dynamically without having to redeploy, without having to, well, sometimes it will redeploy, well, without having to push new code to GitHub.

[00:03:30]
This is a great way to change things out that change depending on what environment you're in. So in development, maybe you have this database, but a staging you have this database, production, you have another database. It's a great way to do that. And also you don't wanna store secret things as plain text in your repo cuz that's a security risk.

[00:03:47]
So that's what a .env is for. That's why it's not in your repo right now because it's not checked into GitHub. So make that file. And then like I said, grab that URL, grab that token, and then you wanna make these two variables in your .env. So you have Turso_Connection_URL, set it equal to that database URL, and then you have Turso_Auth_Token.

[00:04:07]
So if you already have a Turso database from the client side, of course, or from anywhere else, this is the thing that you would need to do, just create your .env file just like you did with the client side course, and add in these two variables here. So you can probably just copy and paste from that repo if you still have it, but feel free to do it again.

[00:04:27]
That's really all you would have to do. If you do make a new database and you're not using the existing one that we did on the client side course, so this is, again, your first time or you made a new database, the last thing you would need to do is push up our database schema to that database.

[00:04:44]
So I have a command in a package JSON called db:push. You can run that command by doing npm run db:push. That's gonna push your schema up to the database that you put in this file. That is necessary. Again, if you already have the database from the client side, this is done for you.

[00:05:02]
You don't need to push it, it's the exact same schema, nothing's changed. If you just made a new Turso database, you have to run this push command to push the schema up. So I'll show you what that looks like so you know when it's done. So if I go here and I say npm run db:push, mine already has it, so yours might not.

[00:05:24]
You might not get the same output that I currently have right now because I already have the schema on there. But regardless, if you do, it'll ask you no or yes. Just say yes, you wanna execute all these statements. And then you know it push when at the end it says changes applied.

[00:05:41]
So once you there, database is good, it's configured, it's ready to go. We never have to worry about the database again.

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