-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (30 loc) · 962 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
// @ts-nocheck
const express = require('express');
const mongoose = require('mongoose')
const User = require('./models/User')
const port = 3000;
const app = express();
mongoose.connect('mongodb://localhost/dbTwo', {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
});
// (async () => {
// const joker = await new User({ name: 'joker' })
// joker.save();
// })()
app.use('/', express.static('public'))
app.use(express.json())
app.get('/db/read', async (req, res) => {
const { colors: { unsorted: unsortedColors } } = await User.findOne({ name: 'joker' });
res.json({ unsortedColors: unsortedColors })
})
app.post('/db/create', async (req, res) => {
const { newColor } = req.body;
await User.updateOne({ name: 'joker' }, { "$addToSet": { "colors.unsorted": newColor } });
res.json(newColor)
res.end()
})
app.listen(port, () => {
console.log("listening to the server");
})