From 98fd9d5c3ed1042aadbe9397ed5c50dbb1a76e16 Mon Sep 17 00:00:00 2001 From: gee92 Date: Tue, 2 Mar 2021 19:50:51 -0500 Subject: [PATCH 1/2] full-stackpd --- rest/index.js | 35 +++++++++++++++++++++++++++++++++-- web/index.html | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/rest/index.js b/rest/index.js index bba5463..0d7e816 100644 --- a/rest/index.js +++ b/rest/index.js @@ -1,4 +1,7 @@ -const express = require('express') + + +const express = require('express') // generate express application +let mysql = require('mysql'); const app = express() const port = 3000 @@ -8,4 +11,32 @@ app.get('/', (req, res) => { app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) -}) \ No newline at end of file +}) + + +function getCustomerData(){ + + +let con = mysql.createConnection({ + host: "localhost", + user: "yourusername", + password: "yourpassword", + database: "classicmodels" +}); + +//con.connect(err => { +// if(err) { + // throw err; +// } + con.query("SELECT * FROM customers", (err, result, fields) => { // if error have reject error + if (err){ + throw err; + } + console.log(result); + con.end(); + }); +}); +} + +let data = getCustomer(); +console.log(data); \ No newline at end of file diff --git a/web/index.html b/web/index.html index 1de928b..f37d3f3 100644 --- a/web/index.html +++ b/web/index.html @@ -7,5 +7,6 @@

Hello Pokemon!

+ \ No newline at end of file From 3a18b70b4ff42929d99d02d70a6cf8b2b5c49084 Mon Sep 17 00:00:00 2001 From: gee92 Date: Tue, 2 Mar 2021 20:29:43 -0500 Subject: [PATCH 2/2] full stack poke --- index.js | 37 ++++++++++++++++++++++++++++++++++++- rest/index.js | 30 ++++++++++++++++-------------- 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index bba5463..206a370 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,6 @@ +let password = "Brother#1" +let mysql = require('password'); + const express = require('express') const app = express() const port = 3000 @@ -8,4 +11,36 @@ app.get('/', (req, res) => { app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) -}) \ No newline at end of file +}) + +let con = mysql.createConnection({ + host: "localhost", + user: "yourusername", + password: "password", + database: "classicmodels" +}); +app.get ('/database', async (req, res)) +con.connect(err => { + if(err) { + throw err; + } + con.query("SELECT * FROM customers", (err, result, fields) => { + if (err){ + throw err; + } + console.log(result); + res.send(result); + }); +}); + + + + + + + + + + + + diff --git a/rest/index.js b/rest/index.js index 0d7e816..83a2326 100644 --- a/rest/index.js +++ b/rest/index.js @@ -9,18 +9,23 @@ app.get('/', (req, res) => { res.send('Hello World!') }) +app.get("/customers", async (req, res) => { + let customerData = await getCustomerData(); + res.send(customerData); +}) + app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) }) -function getCustomerData(){ +async function getCustomerData(){ let con = mysql.createConnection({ host: "localhost", - user: "yourusername", - password: "yourpassword", + user: "root", + password: "password", database: "classicmodels" }); @@ -28,15 +33,12 @@ let con = mysql.createConnection({ // if(err) { // throw err; // } - con.query("SELECT * FROM customers", (err, result, fields) => { // if error have reject error - if (err){ - throw err; - } - console.log(result); - con.end(); - }); -}); -} +let data = await new Promise((resolve, reject) => + con.query("SELECT * FROM customers", (err, result,field) => { // if error have reject error + (err) ? reject(err) : resolve(result); + + }) +}) -let data = getCustomer(); -console.log(data); \ No newline at end of file +con.end(); + return data; \ No newline at end of file