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 bba5463..83a2326 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 @@ -6,6 +9,36 @@ 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}`) -}) \ No newline at end of file +}) + + +async function getCustomerData(){ + + +let con = mysql.createConnection({ + host: "localhost", + user: "root", + password: "password", + database: "classicmodels" +}); + +//con.connect(err => { +// if(err) { + // throw err; +// } +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); + + }) +}) + +con.end(); + return 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