-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (26 loc) · 710 Bytes
/
Copy pathapp.js
File metadata and controls
30 lines (26 loc) · 710 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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const {
getAllUsers,
getUserById,
createUser,
updateUser,
deleteUser,
} = require("./controllers/users");
const app = express();
const PORT = process.env.PORT || 8000;
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.json({ msg: "Hello from node-postres tutorial" });
});
app.get("/users", getAllUsers);
app.get("/users/:id", getUserById);
app.post("/users", createUser);
app.patch("/users/:id", updateUser);
app.delete("/users/:id", deleteUser);
app.listen(PORT, () => {
console.log(`Server started at port ${PORT}`);
});