Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var app = express();
- var bodyParser = require('body-parser');
- // Create application/x-www-form-urlencoded parser
- var urlencodedParser = bodyParser.urlencoded({ extended: true })
- //app.use(express.static('public'));
- //app.use(urlencodedParser);
- //app.use(bodyParser.json);
- app.get('/index.html', function (req, res) {
- res.sendFile( __dirname + "/todo.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(req.body.first_name);
- console.log(response);
- res.end(JSON.stringify(response));
- })
- var server = app.listen(8000, function () {
- var host = server.address().address
- var port = server.address().port
- console.log("Example app listening at http://%s:%s", host, port)
- })
- <html>
- <body>
- <form action="process_post" method="POST">
- First Name: <input type="text" name="first_name"> <br>
- Last Name: <input type="text" name="last_name">
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement