-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
114 lines (113 loc) · 2.67 KB
/
server.js
File metadata and controls
114 lines (113 loc) · 2.67 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
let serverConfig = require("./config/server.config");
// let dbConfig = require("./config/db.config");
let express = require("express");
let app = express();
let router = require("./routes/index");
let bodyParser = require("body-parser");
let ErrorHandler = require("./middlewares/ErrorHandler");
let Product = require("./model/Product");
let Category = require("./model/Category");
let mysql = require("mysql");
app.use(bodyParser.json());
app.use(router);
app.use(ErrorHandler);
let InsetManyValuesInCategories = async () => {
await Category.bulkCreate([
{
name: "Fashion",
},
{
name: "Mobile",
},
{
name: "Electronics",
},
{
name: "Appliances",
},
]);
console.log("Categories bulk insert successful");
};
async function InsertManyValuesInProducts() {
await Product.bulkCreate([
{
name: "Samsung Galaxy Note",
categoryId: 2,
price: 18000,
},
{
name: "Iphone 13",
categoryId: 2,
price: 60000,
},
{
name: "Sony bravia",
categoryId: 3,
price: 40000,
},
{
name: "Boat Rugged",
categoryId: 3,
price: 4000,
},
{
name: "JBL Storm",
categoryId: 3,
price: 9000,
},
{
name: "Vu 5",
categoryId: 3,
price: 32000,
},
]);
console.log("products bulk insert successful");
}
// let init = async () => {
// await dbConfig.sync({ alter: true });
// console.log("Tables create successfully");
// //InsetManyValuesInCategories();
// //InsertManyValuesInProducts();
// };
function saveToDB() {
console.log("inside db");
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "#PerExcellent#",
database: "EcommerceApp_db",
});
// con.connect(function (err) {
// if (err) throw err;
// console.log("Connected!");
// });
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var phone = document.getElementById("phone").value;
var company = document.getElementById("company").value;
var message = document.getElementById("message").value;
con.connect(function (err) {
if (err) throw err;
console.log("Connected!");
var sql =
"INSERT INTO customer (name,email,phone,company,message) VALUES ('" +
name +
"', '" +
email +
"','" +
phone +
"','" +
company +
"','" +
message +
"')";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});
}
app.listen(serverConfig.PORT, function (req, res) {
console.log("server listening @: " + serverConfig.PORT);
// init();
});