From the course: Angular: Creating and Hosting a Full-Stack Site
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Rewrite the listings endpoints
From the course: Angular: Creating and Hosting a Full-Stack Site
Rewrite the listings endpoints
- [Instructor] Now that we have our service set up to connect to the database on startup, and then close that connection when the server is killed, let's move on to seeing how to make actual database queries from our routes. To demonstrate this, what we're going to be doing is rewriting both our getAllListings route and our getListing route to query the database and then send back that data to the client instead of the fake data that we've been using so far. So let's start off with our getAllListings route. The first thing we're going to do here is import the db object that we exported from our database file. So we'll say import db from ../database. And then we're going to modify this route handler here. Instead of returning fakeListings like we've been doing, we're actually going to make a query to our database using the query function of the database object we just imported. So here's what that will look like. We're going…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Why MySQL?2m 16s
-
Install MySQL and MySQL Workbench3m 19s
-
Set up a MySQL database5m 32s
-
Connect to a MySQL database from Node6m 44s
-
Rewrite the listings endpoints8m 20s
-
Create an endpoint for adding views5m 29s
-
Create an endpoint to get a user listing3m 13s
-
Create an endpoint to create listings6m 13s
-
Create an endpoint to edit listings4m 34s
-
Create an endpoint to delete listings2m 33s
-
-
-
-
-