-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (36 loc) · 1.23 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
const express = require ('express');
const cors = require('cors');
const mongoose = require('mongoose');
const app = express();
app.use(cors());
main().catch(err => console.log(err));
async function main() {
const mongoURI = "mongodb+srv://username:[email protected]/todolistDB?retryWrites=true&w=majority";
//await mongoose.connect(mongoURI ,);
//await mongoose.connect(mongoURI);
mongoose.connect(mongoURI)
.then(()=> {
console.log("App connected to database successfully");
app.listen(3000, function()
{
console.log("server started on port 3000");
});
// const todoSchema = new mongoose.Schema({
// task :String
// });
// const Todo = mongoose.model('Todo',todoSchema);
// app.post('/todos', async function(req,res){
// const {task} = req.body;
// const newTodo = new Todo({task});
// try {
// const savedTodo = await newTodo.save();
// res.status(201).json(savedTodo);
// } catch (error) {
// res.status(500).json({ error: 'Failed to add todo' });
// }
// });
app.listen(3000, function(){
console.log("server is running on port 3000");
})
}
)}