forked from UrielRicardo/todolist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (35 loc) · 1.35 KB
/
app.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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const mongoClient = require('mongodb').MongoClient;
app.use(bodyParser.urlencoded({ extended:true }));
app.use(express.static('assets'));
app.set('view engine','ejs');
app.get('/ronaldinho', (req, res) => {
res.render('OI MUNDO');
}
app.get('/', (req, res)=>{
mongoClient.connect('mongodb://dbdogs:w-h5U#Qz4{n@tatooine.mongodb.umbler.com:48145/dbdogs', (err, db)=>{
if(!err){
let todo = req.body.todo;
let collection = db.collection('dogsCollection');
const find = collection.find();
find.toArray((err, results)=>{
res.render('index',{list: results});
});
}
});
});
app.post('/', (req, res)=>{
mongoClient.connect('mongodb://dbdogs:w-h5U#Qz4{n@tatooine.mongodb.umbler.com:48145/dbdogs', (err, db)=>{
if(!err){
let todo = req.body.todo;
let collection = db.collection('dogsCollection');
collection.insert({reminder : todo});
res.redirect('index');
}
});
});
app.listen(3000, ()=>{
console.log('Ouvindo na 3000');
});