title: Sending data from JS file to HTML page
body: <p>I am new to NodeJS. Here is the simple program to send data back and forth from HTML to NodeJS files. My index.html contains a form and div to display the reply received back from server.js:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
      &lt;form action = "http://127.0.0.1:8000/process_post" method = "POST"&gt;
          First Name: &lt;input type = "text" name = "first_name"&gt;  &lt;br&gt;
          Last Name: &lt;input type = "text" name = "last_name"&gt;  &lt;br&gt;
          &lt;input type = "submit" value = "Submit"&gt;
      &lt;/form&gt;
      &lt;div&gt;&lt;%= name %&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Below is the code for server.js:</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var bodyParser = require('body-parser');
  var urlencodedParser = bodyParser.urlencoded({ extended: false })
  app.use(urlencodedParser);
  
  app.get('/', function (req, res) {
      res.sendFile(__dirname + '/index.html');
  });
  
  app.post('/process_post', function (req, res) {
      var name = req.body.first_name+ ' ' + req.body.last_name;   //to send back to HTML
      console.log(name);
      res.send(name);
   });
  
  var server = app.listen(8000);
  </code></pre>
  
  <p>How to update the name in HTML page with the value of name in JS program, each time the form is submitted?</p>