-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (55 loc) · 1.76 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
const express = require('express')
const mongoose = require('mongoose')
const todosRouter = require('./routes/todo')
const cors = require('cors');
const app = express()
const PORT = 3000
//middlewares
app.use(cors());
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
//connection
// mongoose.connect('mongodb://localhost:27017/todolist')
mongoose.connect('mongodb+srv://paragunhale1998:Yhkua19IPIoFJMGt@cluster0.edq0sid.mongodb.net/todolist')
.then(() => console.log('mongoDb Connected')).catch((err) => console.log(err))
//Routes
app.use("/api/v1/todos",todosRouter)
// Define home page route
app.get('/', (req, res) => {
// Define the JSON data for the home page
const homePageData = {
message: 'Welcome to the Todo API!',
endpoints: {
getAllTodos: {
method: 'GET',
path: '/api/v1/todos',
description: 'Get all todos',
},
createNewTodo: {
method: 'POST',
path: '/api/v1/todos',
description: 'Create a new todo',
},
getTodoById: {
method: 'GET',
path: '/api/v1/todos/:id',
description: 'Get a todo by ID',
},
updateTodoById: {
method: 'PATCH',
path: '/api/v1/todos/:id',
description: 'Update a todo by ID',
},
deleteTodoById: {
method: 'DELETE',
path: '/api/v1/todos/:id',
description: 'Delete a todo by ID',
}
}
};
res.json(homePageData);
})
//Server Active
app.listen(PORT, (req, res) => {
console.log(`server started on port ${PORT}`);
})