From the course: Angular: Creating and Hosting a Full-Stack Site
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Connect to a MySQL database from Node
From the course: Angular: Creating and Hosting a Full-Stack Site
Connect to a MySQL database from Node
- [Instructor] So now we have MySQL installed and set up with a working database, which is pretty exciting but this won't actually do us any good yet until we know how to connect to it from our hapi server. And this is actually a fairly simple process, so let's take a look at how it's done. The first thing we have to do is to install the MySQL npm package into our project, which we can do by running npm install mysql, and hitting Enter. And next, we're going to create a new file in our src directory. And we're going to call it database.js. And this is going to contain the logic for setting up a database connection. So here's what that'll look like. We're going to start off by importing the MySQL driver like this. We're going to say import mysql from mysql. And then we're going to create a connection that our server can use to communicate with a local database we created previously. Here's what that'll look like.…
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
-
(Locked)
Install MySQL and MySQL Workbench3m 19s
-
(Locked)
Set up a MySQL database5m 32s
-
(Locked)
Connect to a MySQL database from Node6m 44s
-
(Locked)
Rewrite the listings endpoints8m 20s
-
(Locked)
Create an endpoint for adding views5m 29s
-
(Locked)
Create an endpoint to get a user listing3m 13s
-
(Locked)
Create an endpoint to create listings6m 13s
-
(Locked)
Create an endpoint to edit listings4m 34s
-
(Locked)
Create an endpoint to delete listings2m 33s
-
-
-
-
-