-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 812 Bytes
/
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
import dummyUsers from "./data.js";
import express from "express";
const app = express();
const PORT = 3000;
app.get("/", (req, res) => {
res.status(200);
res.send("Welcome to Rewards VPN");
res.end();
});
app.get("/users", (req, res) => {
res.status(200);
res.send(dummyUsers);
res.end();
});
app.get("/users/:id", (req, res) => {
const id = req.params.id;
const user = dummyUsers.find((user) => user.id === Number(id));
if (user) {
res.status(200);
res.send(user);
} else {
res.status(404);
res.send({ message: "User not found." });
}
res.end();
});
app.listen(PORT, (error) => {
if (!error)
console.log(
"Server is Successfully Running, and App is listening on port " + PORT
);
else console.log("Error occurred, server can't start", error);
});