-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
84 lines (63 loc) · 1.52 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require("dotenv").config();
const express = require('express');
const cors = require('cors');
const User = require('./models/user');
const Food = require("./models/food");
const Music = require("./models/music");
const userRoute = require('./routes/userRoute');
const app = express();
app.use(cors());
app.use(express.json());
const connectToMongo = require('./db/db');
connectToMongo();
app.get('/', (req, res) => {
res.send('Hello World!')
}
)
app.use('/api/v1', userRoute);
app.post('/addfood', async (req, res) => {
const { foodInterest } = req.body;
console.log(foodInterest);
try {
const food = new Food({
foodInterest
});
const savedFood = await food.save();
res.status(200).send(savedFood);
}
catch (err) {
console.log(err)
res.status(400).send(err);
}
}
)
app.post('/addmusic', async (req, res) => {
const { artists } = req.body;
console.log(artists);
try {
const music = new Music({
artists
});
const savedMusic = await music.save();
res.status(200).send(savedMusic);
}
catch (err) {
console.log(err)
res.status(400).send(err);
}
}
)
app.get('/getallusers', async (req, res) => {
try {
const users = await User.find();
res.status(200).send(users);
} catch (err) {
res.status(400).send(err);
}
}
)
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server is running on port: ${PORT}`);
}
)