-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest5.js
37 lines (34 loc) · 1007 Bytes
/
test5.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
const express = require("express");
var cors = require("cors");
var mysql = require("mysql");
const app = express();
app.use(express.json());
app.use(cors());
var con = mysql.createConnection({
host: "localhost",
user: "m_user",
password: "123456",
database: "user",
});
app.listen(4000, () => console.log("App listening on port 4000"));
con.connect(function (err) {
if (err) throw err;
con.query("SELECT * FROM userin", function (err, result, fields) {
if (err) throw err;
console.log(result);
});
});
app.post("/register", (req, res) => {
const id = new Date().getTime().toString();
const username = req.body.data.username;
const password = req.body.data.password;
const email = req.body.data.email;
con.query(
"INSERT INTO userin (ID,username,password,email) VALUES (?,?,?,?) ",
[id, username, password, email],
(err, result) => {
console.log(err);
console.log(id, username, password, email);
}
);
});