Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
let password = "Brother#1"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta change your password :)

let mysql = require('password');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was added by accident, you should remove it and move all server logic to rest/index.js


const express = require('express')
const app = express()
const port = 3000
Expand All @@ -8,4 +11,36 @@ app.get('/', (req, res) => {

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
})

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);
});
});












37 changes: 35 additions & 2 deletions rest/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
const express = require('express')


const express = require('express') // generate express application
let mysql = require('mysql');
const app = express()
const port = 3000

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}`)
})
})


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;
1 change: 1 addition & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
</head>
<body>
<p>Hello Pokemon!</p>
<script src="index.js"></script>
</body>
</html>