Heroku: https://desolate-beyond-88163.herokuapp.com/
Smoothie logger with MySQL, Node, Express, Handlebars and a homemade ORM
In this assignment, you'll create a smoothie 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.
Be sure to utilize the MYSQL Heroku Deployment Guide in order to deploy your assignment.
- Eat-Da-smoothie! is a restaurant app that lets users input the names of smoothies they'd like to eat.
- Whenever a user submits a smoothie's name, your app will display the smoothie on the left side of the page -- waiting to be devoured.
- Each smoothie in the waiting area also has a
Devour it!
button. When the user clicks it, the smoothie will move to the right side of the page. - Your app will store every smoothie 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
smoothie
and clone it to your computer.** - Make a package.json file by running
npm init
from 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
smoothie
directory, create a folder nameddb
. ** -
In the
db
folder, create a file namedschema.sql
. Write SQL queries this file that do the following:- Create the
smoothies_db
. - Switch to or use the
smoothies_db
. - Create a
smoothies
table with these fields:- id: an auto incrementing int that serves as the primary key.
- smoothie_name: a string.
- devoured: a boolean.
- date: a TIMESTAMP.
- Create the
-
Still in the
db
folder, create aseeds.sql
file. In this file, write insert queries to populate thesmoothies
table with at least three entries. -
Run the
schema.sql
andseeds.sql
files into the mysql server from the command line -
Now you're going to run these SQL files.
- Make sure you're in the
db
folder 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.sql
by running the file:source seeds.sql
. - Close out of the MySQL command line tool:
exit
.
- Make sure you're in the
- Inside your
smoothie
directory, create a folder namedconfig
.** - Create a
connection.js
file insideconfig
directory.**- Inside the
connection.js
file, setup the code to connect Node to MySQL. - Export the connection.
- Inside the
- Create an
orm.js
file insideconfig
directory.-
Import (require)
connection.js
intoorm.js
-
In the
orm.js
file, 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
.
-
- Inside your
smoothie
directory, create a folder namedmodels
.- In
models
, make asmoothie.js
file.- Inside
smoothie.js
, importorm.js
intosmoothie.js
- Also inside
smoothie.js
, create the code that will call the ORM functions using smoothie specific input for the ORM. - Export at the end of the
smoothie.js
file.
- Inside
- In
- Inside your
smoothie
directory, create a folder namedcontrollers
. - In
controllers
, create thesmoothies_controller.js
file. - Inside the
smoothies_controller.js
file, import the following:- Express
smoothie.js
- Create the
router
for the app, and export therouter
at the end of your file.
- Inside your
smoothie
directory, create a folder namedviews
.- Create the
index.handlebars
file insideviews
directory. - Create the
layouts
directory insideviews
directory.- Create the
main.handlebars
file insidelayouts
directory. - Setup the
main.handlebars
file so it's able to be used by Handlebars. - Setup the
index.handlebars
to have the template that Handlebars can render onto. - Create a button in
index.handlebars
that will submit the user input into the database.
- Create the
- Create the
All the recommended files and directories from the steps above should look like the following structure:
.
├── config
│ ├── connection.js
│ └── orm.js
│
├── controllers
│ └── smoothies_controller.js
│
├── db
│ ├── schema.sql
│ └── seeds.sql
│
├── models
│ └── smoothie.js
│
├── node_modules
│
├── package.json
│
├── public
│ ├── assets
│ │ ├── css
│ │ │ └── smoothie_style.css
│ │ └── img
│ │ └── smoothie.png
│ └── test.html
│
├── server.js
│
└── views
├── index.handlebars
└── layouts
└── main.handlebars
Attempt to complete homework assignment as described in instructions. If unable to complete certain portions, please pseudocode these portions to describe what remains to be completed.
Now that we have a backend to our applications, we use Heroku for hosting. Please note that while Heroku is free, it will request credit card information if you have more than 5 applications at a time or are adding a database.
Please see Heroku’s Account Verification Information for more details.
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.