-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (37 loc) · 871 Bytes
/
server.js
File metadata and controls
51 lines (37 loc) · 871 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
41
42
43
44
45
46
47
48
49
50
51
const express = require("express");
const mongoose = require("mongoose");
const Cors = require("cors");
const dotenv = require("dotenv");
dotenv.config();
const {
getTodos,
createTodo,
updateTodo,
deleteTodo,
} = require('./controllers/todoController');
// App config
const app = express();
const port = process.env.PORT || 8000;
const connectionURL = process.env.MONGO_URI;
// // Middlewares
// // Convert to Json
app.use(express.json());
app.use(Cors());
// // DB config
mongoose
.connect(connectionURL)
.then(() => {
app.listen(port, () => console.log(`Running on port: ${port}`))
})
.catch((err) => {
console.log(err);
});
// API Endpoints
// Get todos list
app.get("/todos", getTodos);
// Create a new Todo
app.post("/todos", createTodo);
// Update a Todo
app.put("/todos/:id", updateTodo);
// Delete a Todo
app.delete("/todos/:id", deleteTodo);