-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (34 loc) · 903 Bytes
/
server.js
File metadata and controls
40 lines (34 loc) · 903 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
33
34
35
36
37
38
39
40
require('dotenv').config();
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
const express = require("express");
const path = require("path");
const app = express();
const port = process.env.PORT;
app.use(express.json());
app.use(express.static(path.join("screen")));
app.post("/task", async (req, res) => {
const { content } = req.body;
const tasks = await prisma.task.create({
data: {
content,
},
});
res.json(tasks);
});
app.get("/task", async (req, res) => {
const tasks = await prisma.task.findMany();
res.json(tasks);
});
app.delete("/task", async (req, res) => {
const taskId = req.body.id;
const deleteTask = await prisma.task.delete({
where: {
id: Number(taskId)
}
});
res.json(deleteTask);
})
app.listen(port, () => {
console.log(`Server Express listening on port ${port}`);
});