Saturday, 22 April 2017

How to get body parameters in node.js

Well I had just started programming in node.js. I am stuck at one place.

I am getting my request parameter like

response: --------------------------e2a4456320b2131c


sent
--------------------------e2a4456320b2131c
Content-Disposition: form-data; name="is_test"

true
--------------------------e2a4456320b2131c
Content-Disposition: form-data; name="success"

true
--------------------------e2a4456320b2131c--

How can i fetch all this params :

is_test , success and etc.

Here is my code :

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

var app = express();

app.use(bodyParser.json());

exports.helloWorld = functions.https.onRequest((request, response) => {
                                                    var body = "";

                                    request.on('data', function (data) {
                                                          body += data;
                                                      });
                                    request.on('end', function() {                                                             
                                                             console.log('response: ' + body);




                                                         });                                            

     });



via Sunny Shah

No comments:

Post a Comment