In this video we are going to learn about Handling the post request.
POST and GET are two common HTTP Request used for building REST API's.
Both of these calls are used for some special purpose.
GET request are used to fetch data from specified resource and POST are used to submit data to a specified resource.
Express version 4 and above require extra middle-ware layer to handle a POST request.
This middle-ware is called as 'bodyParser'.
So let install the body parser.
So go to the command prompt and run the command.


npm install body-parser


Now we have to import this package in our project and tell Express to use this as middle-ware.
So go to the index.js and import the package.


var bodyParser = require(\"body-parser\");


Now configure express to use body parser as middleware.


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



Now we can use app.post express router to handle POST request.
Now create a route.


app.get('/login',function(req,res){
res.render('login');
});



Now create a view.
So go to the views and create new file login.ejs.
Now open login.ejs and write the following code.


<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<title>Login</title>
</head>
<body>
<form method=\"POST\" action=\"/post\">
<div class=\"form-group\">
<label for=\"email\">Email </label>
<input type=\"email\" class=\"form-control\" id=\"email\">
</div>
<div class=\"form-group\">
<label for=\"password\">Password</label>
<input type=\"password\" class=\"form-control\" id=\"password\">
</div>
<button type=\"submit\" class=\"btn btn-primary\">Submit</button>
</form>
</body>
</html>


Add create the post route.
So go to the index.js and lets create the route.


app.post('/post',function(request,response){
var email=request.body.email;
var password=request.body.password;
res.send('Email'+email + \" Password: \"+password);
});



Now lets run this.
So go to the command prompt and run the index.js file.


node index.js


Now its running.
So go to the browser an.
Just go to the url /login.
Now fill email and password here and click on submit button.
You can see here the email and password has been submitted.
So in this way you can handle the post request.