Express Post form Data – d

In this example we use POST method to pass data from client to server. POST is frequently used for FORM submissions.

First we create our project run npm init and name project as postdata and create file called app.js in our project and add the following code in app.js

const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');

const app = express();

app.use(bodyParser.urlencoded({extended: false}));

// Set Static path
app.use(express.static(path.join(__dirname, 'public')));'/student', (req, res) => {
  let name = req.body.firstName + ' ' + req.body.lastName;
  let email =;

  res.send('Student name : ' + name + '<br/>' + 'Student email :' + email);

app.listen(3000, () => {
  console.log('Server started on port 3000...');

We are using expressjs and body-parse, in command line install both package as
$ npm install express –save
$ npm i body-parser –save

Create a folder public in our root folder and create index.html add the following code, so we can add form data in index.html

<!DOCTYPE html>

  <meta charset="utf-8">
  <title>Express Post</title>

  <div class="conatiner">
    <h2>Post Form data in Express Nodejs</h2>

    <form method="post" action="/student">
      First name:<br/>
      <input type="text" name="firstName" placeholder="First name">
      Last name:<br/>
      <input type="text" name="lastName" placeholder="Last name">
      <input type="text" name="email" placeholder="Email">
      <input type="submit" value="Submit">
Spread the love

Leave a Comment

Your email address will not be published.

Scroll to Top