-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (24 loc) · 771 Bytes
/
Copy pathapp.js
File metadata and controls
32 lines (24 loc) · 771 Bytes
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
const express = require("express");
const app = express();
const port = 3000;
const mysql = require("./db/mysql.js");
mysql.connect();
// route
const user = require("./user/user.js");
const category = require("./category/category.js");
// prefix
app.use("/api/user", user);
app.use("/api/category", category);
app.get("/", (req, res) => res.send("Hello Express!"));
app.get("/user/:name/:age", function (req, res) {
var params = req.params;
console.log(params);
mysql.query("select * from user", function (err, result) {
if (err) console.log(err);
else {
console.log(result);
}
});
res.send("User Name : " + params.name + " / User Age : " + params.age);
});
app.listen(3000, () => console.log("Server listens on port ", port, "..."));