-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
61 lines (48 loc) · 1.25 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
54
55
56
57
58
59
60
61
var express = require('express');
//parserek
var bodyParser = require('body-parser');
var multer = require('multer');
var upload = multer();
//db
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/node-todo-app');
//app deklaralas
var app = express();
// define model =================
var Todo = mongoose.model('Todo', {
text : String
});
//view
app.set('view engine', 'pug');
app.set('views', './views');
//parse
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(upload.array());
//static fileok a public mappaban
app.use(express.static('public'));
//fooldal
app.get('/', function (req, res) {
console.log('request for home');
Todo.find(function(err, todos) {
var texts = [];
for (var i = 0; i < todos.length; ++i) {
texts.push(todos[i].text);
}
console.log(texts);
res.render('home', {todos: texts});
});
});
//todo hozzaadas
app.get('/add_todo', function(req, res) {
console.log('request for add_todo');
res.render('add_todo');
});
app.post('/add', function(req, res) {
res.render('add');
console.log('add todo:' + req.body.todo_text);
Todo.create({text: req.body.todo_text})
});
app.listen(3000, function () {
console.log('The server is set up, and listening on port 3000.');
});