-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (40 loc) · 1.08 KB
/
index.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
const express = require("express");
const app = express();
let port = 8080;
app.get("/", (req, res) => {
console.log("You are on root path");
res.send("root path");
});
app.get("/apple", (req, res) => {
res.send("You connected to apple path");
});
app.get("/mango", (req, res) => {
res.send("You connected to mango path");
});
app.get("/:username/:id", (req, res) => {
let { username, id } = req.params;
let text = `<h1>Connected to ${username} with id of ${id}<h1/>`;
res.send(text);
});
app.get("/search", (req, res) => {
let { q } = req.query;
if (!q) {
res.send("Nothing Searched");
}
res.send(`<h2>search result for query:${q}<h2/>`);
});
app.get("*", (req, res) => {
res.send("Wrong path");
});
// app.use((req, res) => {
// console.log("Request received");
// // res.send({
// // name: "Affan",
// // class: "Student",
// // });
// let code = "<h1>I love Programming<h1/>";
// res.send(code);
// });
app.listen(port, function () {
console.log(`Server is listening to port ${port}`);
});