equal
deleted
inserted
replaced
|
1 var express = require('express'); |
|
2 var bodyParser = require('body-parser'); |
|
3 |
|
4 var app = express(); |
|
5 app.use(bodyParser.urlencoded({ extended: true })); |
|
6 |
|
7 // sending the form |
|
8 app.get('/', function(req, res){ |
|
9 var html = '<form action="/" method="post">' + |
|
10 'Login: <input type="text" name="login" /><br>' + |
|
11 'Password: <input type="password" name="pass" /><br>' + |
|
12 '<button type="submit">Submit</button>' + |
|
13 '</form>'; |
|
14 res.send(html); |
|
15 }); |
|
16 |
|
17 // receiving data |
|
18 app.post('/', function(req, res){ |
|
19 var html = 'Received login: ' + req.body.login + '<br>' + |
|
20 'Received password: ' + req.body.pass + '<br>' + |
|
21 '<a href="/">Try again</a>'; |
|
22 res.send(html); |
|
23 }); |
|
24 |
|
25 // starting the server |
|
26 app.listen(8000); |
|
27 console.log("Server running at http://127.0.0.1:8000/"); |