-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
48 lines (39 loc) · 1.25 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
require("dotenv").config();
const express = require("express");
const PORT = process.env.PORT || 5000;
const cors = require("cors");
// mongoose is used to create Schemas and Database for the application, it is a ODM, Object Data Modelling
// Like you can Create a schema that for every blog post saved in DB there must be a title, author, date, content
const mongoose = require("mongoose");
// const workoutRoutes = require("./routes/workouts");
const userRoutes = require("./routes/user");
const dogRoutes = require("./routes/dog");
const app = express();
app.use(cors());
// middleware code is executes getting responsce from server and sending a response
// global middleware
app.use(express.json());
// connection to DB
mongoose
.connect(process.env.MONGO_URI)
.then(() => {
app.listen(PORT, () => {
console.log("connected to data server started at !!!", PORT);
});
})
.catch((err) => {
console.log(err);
});
// app.use(cors(corsOpts))
app.use((req, res, next) => {
console.log(req.path, req.method);
next();
});
// routes
app.get("/", cors(), (req, res) => {
res.json({ msg: "Welcome to the app" });
});
// app.use("/api/workouts", workoutRoutes);
app.use("/api/user", userRoutes)
app.use("/api/user", dogRoutes)
//export default app;