a restaurant app that lets users input the names of burgers they'd like to eat.
In this assignment, you'll create a burger logger with MySQL, Node, Express, Handlebars and a homemade ORM (yum!). Be sure to follow the MVC design pattern; use Node and MySQL to query and route data in your app, and Handlebars to generate your HTML.
You will be fully capable of doing this homework by the end of Saturday's class.
-
Eat-Da-Burger! is a restaurant app that lets users input the names of burgers they'd like to eat.
-
Whenever a user submits a burger's name, your app will display the burger on the left side of the page -- waiting to be devoured.
-
Each burger in the waiting area also has a
Devour it!button. When the user clicks it, the burger will move to the right side of the page. -
Your app will store every burger in a database, whether devoured or not.
-
Check out this video of the app for a run-through of how it works.
-
Create a GitHub repo called
burgerand clone it to your computer. -
Make a package.json file by running
npm initfrom the command line. -
Install the Express npm package:
npm install express --save. -
Create a server.js file.
-
Install the Handlebars npm package:
npm install express-handlebars --save. -
Install the method-override npm package:
npm install method-override --save. -
Install the body-parser npm package:
npm install body-parser --save. -
Install MySQL npm package:
npm install mysql --save. -
Require the following npm packages inside of the server.js file:
- express
- method-override
- body-parser
-
Inside your
burgerdirectory, create a folder nameddb. -
In the
dbfolder, create a file namedschema.sql. Write SQL queries this file that do the following:- Create the
burgers_db. - Switch to or use the
burgers_db. - Create a
burgerstable with these fields:- id: an auto incrementing int that serves as the primary key.
- burger_name: a string.
- devoured: a boolean.
- date: a TIMESTAMP.
- Create the
-
Still in the
dbfolder, create aseeds.sqlfile. In this file, write insert queries to populate theburgerstable with at least three entries. -
Run the
schema.sqlandseeds.sqlfiles into the mysql server from the command line -
Now you're going to run these SQL files.
-
Make sure you're in the
dbfolder of your app. -
Start MySQL command line tool and login:
mysql -u root -p. -
With the
mysql>command line tool running, enter the commandsource schema.sql. This will run your schema file and all of the queries in it -- in other words, you'll be creating your database. -
Now insert the entries you defined in
seeds.sqlby running the file:source seeds.sql. -
Close out of the MySQL command line tool:
exit.
-
-
Inside your
burgerdirectory, create a folder namedconfig. -
Create a
connection.jsfile insideconfigdirectory.-
Inside the
connection.jsfile, setup the code to connect Node to MySQL. -
Export the connection.
-
-
Create an
orm.jsfile insideconfigdirectory.-
Import (require)
connection.jsintoorm.js -
In the
orm.jsfile, create the methods that will execute the necessary MySQL commands in the controllers. These are the methods you will need to use in order to retrieve and store data in your database.selectAll()insertOne()updateOne()
-
Export the ORM object in
module.exports.
-
##stopped here*** Model setup ##Model setup
-
Inside your
burgerdirectory, create a folder namedmodels.-
In
models, make aburger.jsfile.-
Inside
burger.js, importorm.jsintoburger.js -
Also inside
burger.js, create the code that will call the ORM functions using burger specific input for the ORM. -
Export at the end of the
burger.jsfile.
-
-
-
Inside your
burgerdirectory, create a folder namedcontrollers. -
In
controllers, create theburgers_controller.jsfile. -
Inside the
burgers_controller.jsfile, import the following:- Express
burger.js
-
Create the
routerfor the app, and export therouterat the end of your file.
-
Inside your
burgerdirectory, create a folder namedviews.-
Create the
index.handlebarsfile insideviewsdirectory. -
Create the
layoutsdirectory insideviewsdirectory.-
Create the
main.handlebarsfile insidelayoutsdirectory. -
Setup the
main.handlebarsfile so it's able to be used by Handlebars. -
Setup the
index.handlebarsto have the template that Handlebars can render onto. -
Create a button in
index.handlebarsthat will submit the user input into the database.
-
-
All the recommended files and directories from the steps above should look like the following structure:
.
├── config
│ ├── connection.js
│ └── orm.js
│
├── controllers
│ └── burgers_controller.js
│
├── db
│ ├── schema.sql
│ └── seeds.sql
│
├── models
│ └── burger.js
│
├── node_modules
│
├── package.json
│
├── public
│ ├── assets
│ │ ├── css
│ │ │ └── burger_style.css
│ │ └── img
│ │ └── burger.png
│ └── test.html
│
├── server.js
│
└── views
├── index.handlebars
└── layouts
└── main.handlebars
This is a really tough homework assignment, but we want you to put in your best effort to finish it.
If you have any questions about this project or the material we have covered, please post them in the community channels in slack so that your fellow developers can help you! If you're still having trouble, you can come to office hours for assistance from your instructor and TAs.
Good Luck!
Coding Boot Camp (C) 2016. All Rights Reserved.