An express-server but with a mysql database.
First, get the example:
git clone git@github.com:cmda-be/course-17-18.git
cd course-17-18/examples/mysql-server
npm install
Then, log into mysql:
mysql -u your-username -p
# Enter your password
…and run the following SQL to set up a database and populate a movies table:
CREATE DATABASE IF NOT EXISTS mymoviewebsite;
USE mymoviewebsite;
CREATE TABLE IF NOT EXISTS movies (
id INT NOT NULL AUTO_INCREMENT,
cover TEXT CHARACTER SET utf8,
title TEXT CHARACTER SET utf8,
description TEXT CHARACTER SET utf8,
plot TEXT CHARACTER SET utf8,
PRIMARY KEY (id)
);
-- Add some movies like so:
INSERT INTO movies (title, plot, description) VALUES (
'Evil Dead',
'Five friends travel to a cabin in …',
'Five friends head to a remote cabin, …'
);
INSERT INTO movies (title, plot, description) VALUES (
'The Shawshank Redemption',
'Two imprisoned men bond over a …',
'Andy Dufresne is a young and …'
);
Now, add a .env
file with the following info (replacing the values
with actual values):
DB_HOST=localhost
DB_USER=myusername
DB_NAME=mydatabase
DB_PASSWORD=mypassword
Finally, start the server with:
npm start
The following commits show how this example was created:
dd116ac
add mysql, dotenv as a dependencies9d49c2d
add gitignore390c717
add mysql connection88e38b5
use mysql for list of movieseea52db
use mysql for detail of movie73bb5ac
use mysql to add a movied23133e
use mysql to remove a moviead6ed8a
remove superfluous dataf6cb536
remove superfluous dependencies