Express by Examples

POST variables with body-parser module

To be able to POST variables from FORM use 'body-parser' module.

 

Installation

$ npm install body-parser

 

Integration into app.js

var bodyParser = require('body-parser');

app.use(bodyParser.json());  //to support JSON encoded bodies
app.use(bodyParser.urlencoded({ extended: false })); //to support URL encoded bodies

 

 

Notice:

The body-parser module don't support multipart data. So don't put enctype="multipart/form-data" inside your FORM tag.

<form action="demo_post_enctype.asp"
method=
"post" enctype="multipart/form-data">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
</form>