Get POST data In Express.js – Node.js


Get POST data In Express.js – Node.js: If you are using the Express.Js for Node.js you can get the post query strings ie. post parameters. Express.js is basically high class, high performance web development which is used for node.js. Here we are going to explain how to get the Post parameters passed from a Form using post method.


Get POST data In Express.js – Node.js

The html & Javascript Part are as below –

Html Part –

Suppose we have following form with the three input fields as below. We are going to post these values using this form.

Get POST data In Express.js – Node.js:

<form method="post" action="/">
    <input type="text" name="customer[name]">
    <input type="text" name="customer[email]">
	<input type="text" name="customer[phone]">
    <input type="submit" value="Submit">
</form>

Javascript Part-

Here is javascript part in which we will get all the three fields posted using the form –

Get POST data In Express.js – Node.js:

app.use(express.bodyParser());
app.post('/', function(request, response){
    console.log(request.body.customer.name);
    console.log(request.body.customer.email);
	console.log(request.body.customer.phone);
});

Thus you can access any field posted from the Form.


Advertisements

Add Comment