SHARE
TWEET

form

rakib-rs Oct 18th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require('express');  
  2. var app = express();  
  3. var bodyParser = require('body-parser');  
  4. // Create application/x-www-form-urlencoded parser  
  5. var urlencodedParser = bodyParser.urlencoded({ extended: true })  
  6. //app.use(express.static('public'));
  7. //app.use(urlencodedParser);
  8. //app.use(bodyParser.json);
  9. app.get('/index.html', function (req, res) {  
  10.    res.sendFile( __dirname + "/todo.htm" );  
  11. })  
  12. app.post('/process_post', urlencodedParser, function (req, res) {  
  13.    // Prepare output in JSON format  
  14.    response = {  
  15.        first_name:req.body.first_name,  
  16.        last_name:req.body.last_name  
  17.    };  
  18.    console.log(req.body.first_name);
  19.    
  20.    console.log(response);  
  21.    res.end(JSON.stringify(response));  
  22. })  
  23. var server = app.listen(8000, function () {  
  24.   var host = server.address().address  
  25.   var port = server.address().port  
  26.   console.log("Example app listening at http://%s:%s", host, port)  
  27. })  
  28.  
  29.  
  30.  
  31. <html>  
  32. <body>  
  33. <form action="process_post" method="POST">  
  34. First Name: <input type="text" name="first_name">  <br>  
  35. Last Name: <input type="text" name="last_name">  
  36. <input type="submit" value="Submit">  
  37. </form>  
  38. </body>  
  39. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top