Create a burger web applicaion with MySQL, Node, Express, Handlebars and applying ORM, MVC Pattern then deploy to heroku.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
# Install body-parser
npm i body-parser
# Install middleware
npm i express
# Install UI Templete Engine
npm i express-handlebars
# Install MySQL
npm i mysql
# Run
node server.js or npm start (using nodemon)
To get Note Taker, after downloading, you need to make sure Git Bash terminal open and looking at the correct folder. When you are within the correct location, you may type the following commands to ask her for information:
- node server.js
- Proceeds as follows:
To use this applicaion, Clone the applicaion to your local git repository or directory:
- In your terminal, git clone https://github.com/EunsooJung/Burger.git
To start:
- You have to install npm packages depend on my package.json file: "npm install"
- Open your terminal then "node server.js"
-
Project structure
-
Source Code Check point
-
folder "config": It has two files 'connection.js' and 'orm.js'
- connection.js: To connection to mysql or heroku mysql database ```javascript if (process.env.JAWDB_URL) { connection = mysql.createConnection(process.env.JAWDB_URL); } else { connection = mysql.createConnection({ host: 'nba02whlntki5w2p.cbetxkdyhwsb.us-east-1.rds.amazonaws.com', user: 'jvqzqgkg2h65um00', password: 'xbsqx1w226e6qjes', database: 'pcuy624fcat5xziy' /* host: 'localhost', user: 'root', password: 'password', database: 'burgers_db' */ }); } ``` - orm.js: It's define the object-relational mapping logic. - Implemented helper function to convert object key/value pairs to SQL syntax ```javascript function objToSql(ob) { var arr = []; // loop through the keys and push the key/value as a string int arr for (var key in ob) { var value = ob[key]; // check to skip hidden properties if (Object.hasOwnProperty.call(ob, key)) { // if string with spaces, add quotations (Cheese Burger => 'Cheese Burger') if (typeof value === "string" && value.indexOf(" ") >= 0) { value = "'" + value + "'"; } arr.push(key + "=" + value); } } // translate array of strings to a single comma-separated string return arr.toString(); } ```
-
Models layer: ** burger.js **:
- Implements to call the ORM functions using burger specific input for the ORM.
var burger = { selectAll: function(cb) { orm.selectAll('burger', function(res) { cb(res); }); },
- View layer: Applied handlebars template engine
- views/layouts/main.handlebars
- views/index.handlebars
- Controllers layer:
- burgers_controllers.js: Create all of this Burger web application's routes (maps) using a exppress router.
-
// route default landing page
router.get('/', function(req, res) {
burger.selectAll(function(data) {
var burgersObject = {
burgers: data
};
// console.log(burgersObject);
res.render('index', burgersObject);
});
});
-
server.js:
- Setup Burger web applicaion's environments (npm package dependencies)
- Import routes to access.
const routes = require('./controllers/burgers_controllers');
- Michael(Eunsoo)Jung
This project is licensed under the MIT License