Complete Intro to SQLite

SQLite App Project Setup

Complete Intro to SQLite

Check out a free preview of the full Complete Intro to SQLite course

The "SQLite App Project Setup" Lesson is part of the full, Complete Intro to SQLite course featured in this preview video. Here's what you'd learn in this lesson:

Brian walks through the project setup for a application built with SQLite and Node.js. Fastify is used to create a basic Node.js server. The sqlite3 NPM module provides APIs for working with a local SQLite database.

Preview
Close

Transcript from the "SQLite App Project Setup" Lesson

[00:00:00]
>> Brian Holt: Because I like grounding everything in code, I'm gonna make you write some code now. We're actually gonna write a little bit of Node.js. So I have a repo here, go ahead and open that, it should be the sqlite-app.
>> Brian Holt: We're gonna be reusing this a bunch of different times.

[00:00:18]
>> Brian Holt: This is a invoice app,
>> Brian Holt: That reads from our invoice table, that's what this data.db is, it's just a fresh copy of that Chinook database.
>> Brian Holt: So I'm gonna get out of this, exit.
>> Brian Holt: This is just a fresh copy, yep, fresh copy of that same,
>> Brian Holt: Same repo.

[00:00:49]
I'm gonna run npm install, if you haven't done that already, I have. So then you should have, let's just look at this in VS Code. I don't need that anymore, Don't Save, all right.
>> Brian Holt: You can see here, I don't have too many files here, let's look at the package.json.

[00:01:20]
By the way, don't look at invoice-completed, that's the cheater answer place. And I want you to try first before you do that, okay? So just to look quickly at package.json here, this is a Fastify server. You don't really need to care, I don't expect you to write any Fastify code, really, and I've tried to pre-write all the Fastify code for you.

[00:01:47]
It is using HTMX and Handlebars, mostly cuz I hadn't messed around with HTMX before, so I did, it's kinda fun. Sqlite3, that's the official SQLite driver for Node.js. I will say I don't think it's the best one, but I wanted you to start there. So that eventually when you choose something different, you know why you're choosing something different.

[00:02:10]
And that's about it, and then I have nodemon on here to help you with your development cycle. So if you come in here, you've run npm install, you should be able to do npm run dev, and that should start your server. You should see some output like that.

[00:02:31]
And then you should be able to go to localhost.8080.
>> Brian Holt: And you should end up with something like this.
>> Brian Holt: I tried to make the most generic, worse logo that I could, with just a terrible, your business in our hands. Hopefully, I succeeded in making you throw up a little bit in your mouth, in terms of just how generic business that is.

[00:02:55]
I just finished business school, so I business.
>> Brian Holt: Yeah, and basically, what you'll do here is you'll put 10 in here, you'll say Get Invoice. It'll hit the database, which you can see it already. I've written all of the front end code, so you shouldn't have to touch the front end at all.

[00:03:13]
Everything will get logged out here. And just to prove my point, if you go to network here. And let's just clear, so if I get invoice, you can see it makes an invoice request. And it'll give you a response of invoice and lines, okay, that's how that all works.

[00:03:34]
And eventually, if you get it all right, the invoice should populate here, as long as you call it the same thing that I did.
>> Brian Holt: Okay, so that's what server.js does. It just registers all the functions here, that's all it really is doing, sets up all the front end stuff.

[00:03:51]
I was very lazy in how I did everything. I did not want you to have to start a V8 server or Parcel or something like that, so it's all done with no build step. There's an index.js that includes a font and just some basic HTMX. The data.db, that's the one that we were talking about already.

[00:04:13]
There's a logo, there's some styles.

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