-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
65 lines (56 loc) · 1.39 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const express = require("express");
// const path = require("path");
const path = require("mysql");
const mysql = require("mysql");
const app = express();
//
// app.use("/static", express.static(path.resolve(__dirname, "frontend", "static")));
//
//
//
// app.listen(process.env.PORT || 3000, () => console.log("Server running..."));
//
app.listen('3000',() => {
console.log('Server started on port 3000');
});
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '123456',
database: 'modemysql'
});
//Connect
db.connect((err) => {
if(err){
throw err;
}
console.log('Mysql conected..');
});
app.get('createdb', (req, res) => {
let sql = 'CREATE DATABASE nodemysql';
db.query(sql, (err, result) => {
if(err) throw err;
console.log(result);
res.send('Database created');
});
});
// app.get("/*", (req, res) => {
// res.sendFile(path.resolve(__dirname, "frontend", "index.html"));
// });
const con = mysql.createConnection({
host: 'localhost',
user: 'root',
// passworld: '123456'
});
con.connect(function(err) {
if (err) throw err;
console.log('Connected');
});
con.connect(function(err){
if (err) throw err;
console.log('Connected');
con.query('CREATE DATABASE express_db', function (err, result){
if (err) throw err;
console.log('database created');
})
});