forked from egoing/server_side_javascript_tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
76 lines (76 loc) · 1.84 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.locals.pretty = true;
app.set('view engine', 'jade');
app.set('views', './views');
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: false }))
app.get('/form', function(req, res){
res.render('form');
});
app.get('/form_receiver', function(req, res){
var title = req.query.title;
var description = req.query.description;
res.send(title+','+description);
});
app.post('/form_receiver', function(req, res){
var title = req.body.title;
var description = req.body.description;
res.send(title+','+description);
});
app.get('/topic/:id', function(req, res){
var topics = [
'Javascript is....',
'Nodejs is...',
'Express is...'
];
var output = `
<a href="/topic/0">JavaScript</a><br>
<a href="/topic/1">Nodejs</a><br>
<a href="/topic/2">Express</a><br><br>
${topics[req.params.id]}
`
res.send(output);
})
app.get('/topic/:id/:mode', function(req, res){
res.send(req.params.id+','+req.params.mode)
})
app.get('/template', function(req, res){
res.render('temp', {time:Date(), title:'Jade'});
})
app.get('/', function(req, res){
res.send('Hello home page');;
});
app.get('/dynamic', function(req, res){
var lis = '';
for(var i=0; i<5; i++){
lis = lis + '<li>coding</li>';
}
var time = Date();
var output = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
Hello, Dynamic!
<ul>
${lis}
</ul>
${time}
</body>
</html>`;
res.send(output);
});
app.get('/route', function(req, res){
res.send('Hello Router, <img src="/route.png">')
})
app.get('/login', function(req, res){
res.send('<h1>Login please</h1>');
});
app.listen(3000, function(){
console.log('Conneted 3000 port!');
});