var express = require('express');
var app = express();
var bodyParser = require('body-parser');
// Create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.use(express.static('public'));
app.get('/index.htm', function (req, res) {
res.sendFile(__dirname + "/" + "index.htm");
})
app.post('/process_post', urlencodedParser, function (req, res) {
// Prepare output in JSON format
response = {
first_name:req.body.first_name,
last_name:req.body.last_name
};
console.log(response);
res.end(JSON.stringify(response));
})
var server = app.listen(8081, function() {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: false })
body-parser有什麼用?app.post('/process_post', urlencodedParser, function (req, res)
任何人都可以請解釋上述三行代碼的目的,有什麼用身體解析器的?