-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (33 loc) · 992 Bytes
/
server.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
require("dotenv").config();
const cors = require("cors");
const express = require("express");
const { sql } = require("@vercel/postgres");
const { createUser, getAllUsers, editUser } = require("./controllers/users");
const {
getAllNotes,
getNotesByUser,
getIndividualNoteByUser,
postNote,
deleteNote,
editNote,
} = require("./controllers/notes");
const app = express();
app.use(express.json());
app.use(cors());
app.get("/", (req, res) => {
res.json({ msg: "Hello from the Notes App - This is the demo" });
});
app.post("/users", createUser);
app.get("/users", getAllUsers);
app.get("/notes", getAllNotes);
app.get("/:user/notes", getNotesByUser);
app.get("/:user/notes/:id", getIndividualNoteByUser);
app.post("/:user/notes", postNote);
//New function to edit users. done!
app.patch("/users", editUser);
app.delete("/notes/:id", deleteNote);
app.patch("/notes/:id", editNote);
app.listen(3000, () => {
console.log("Server started on port 3000");
});
//cors added