-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (41 loc) · 1.24 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
const express = require("express");
const app = express();
// const port = 3000;
const port = process.env.PORT || 3000
const mongoose = require("mongoose");
const cors = require("cors");
app.use(cors());
//import routesAuth
const authRoute = require("./auth/userAuth");
const addTask = require("./routes/addTask");
const fetchTask = require("./routes/fetchTask");
const deleteTask = require("./routes/deleteTask");
const progressTask = require("./routes/progressTask");
// for cloud Database
const { DB_CONNECT } = require("./config/constants");
// connect to DB
mongoose.connect(
DB_CONNECT,
{ useNewUrlParser: true, useUnifiedTopology: true },
() => console.log("Connected to DB!")
);
//for local Database
// mongoose.connect(
// "mongodb://localhost/taskManager",
// {
// useNewUrlParser: true,
// useUnifiedTopology: true,
// },
// () => console.log("Connected to DB!")
// );
//middleware
app.use(express.json());
//route middleware
app.use("/api/user", authRoute);
app.use("/api/user/addtask", addTask);
app.use("/api/user/tasks", fetchTask);
app.use("/api/user/deletetask", deleteTask);
app.use("/api/user/progressupdate", progressTask);
app.listen(port, () =>
console.log(`Server is up and running on localhost ${port}`)
);