-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
95 lines (79 loc) · 2.46 KB
/
app.js
File metadata and controls
95 lines (79 loc) · 2.46 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var express= require('express');
var bodyParser= require('body-parser');
var mysql=require('mysql');
var url=require('url');
var app=express();
// var urlencodedParser=bodyParser.urlencoded({extended:false});
var {showUser} = require('./routes/index');
var {addUserPage,addUser,editUser,editUserPage,deleteUser}= require('./routes/data');
app.set("view engine","ejs");
app.use(express.static("assets"));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// var db=mysql.createConnection ({
// host: 'localhost',
// user:'root',
// database: 'aarg',
// })
// db.connect(function(err){
// if(err){
// throw err;
// }
// console.log('Connected to Database!');
// });
// global.db=db;
// let query="CREATE DATABASE arg;
// CREATE TABLE IF NOT EXISTS `users` (
// `id` int(5) NOT NULL AUTO_INCREMENT,
// `name` varchar(255) NOT NULL,
// `stid` varchar(255) NOT NULL,
// `boos` varchar(255) NOT NULL,
// PRIMARY KEY (`id`)
// ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
// var db=mysql.createConnection ({
// host: 'localhost',
// user:'root',
// database: 'aarg',
// })
// db.connect(function(err){
// if(err){
// throw err;
// }
// console.log('Connected to Database!');
// });
// global.db=db;
var db = mysql.createConnection({
host: "localhost",
user: "root",
});
db.connect(function(err) {
if (err) throw err;
console.log("Connected!");
db.query("CREATE DATABASE IF NOT EXISTS lib", function (err, result) {
if (err) throw err;
console.log("Database created");
});
});
global.db=db;
var db = mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'lib'
});
db.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "CREATE TABLE IF NOT EXISTS users (id int(5) NOT NULL AUTO_INCREMENT,name varchar(255) NOT NULL,stid varchar(255) NOT NULL,boos varchar(255) NOT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
db.query(sql, function (err, result) {
if (err) throw err;
console.log("Table created");
});
});
global.db=db;
app.get('/', showUser);
app.get('/add',addUserPage);
app.post('/add',addUser);
app.get('/edit:id',editUserPage);
app.post('/edit:id',editUser);
app.get('/delete:id',deleteUser);
app.listen(8080);