How to read a post request data in node.js. When client send a post request?

Not applicable

When we send a post request to node.js how to read the data from the payload. Apigee-access module is not supporting in our environment is there any other way to read the data from the payload.

Solved Solved
0 4 49.6K
2 ACCEPTED SOLUTIONS

This needs to be handled using express. Please refer to generic node.js POST data handling logic,

For example: http://stackoverflow.com/questions/4295782/how-do-you-extract-post-data-in-node-js

Wondering what is the issue with apigee-access module ?

View solution in original post

Not applicable

@Kodandapani, As @Madhan Sadasivam mentioned you can try express but as apigee-access module is not supported on the Edge release you are or you can try the below on your node.js script itself and see if it helps you

@Madhan Sadasivam, do you see any issues with running the below code on edge ? I tried and it works fine .

var svr = http.createServer(function(req, resp) {
   var body = "";
  req.on('data', function (chunk) {
    body += chunk;
  });
  req.on('end', function () {
    console.log('body: ' + body);
    var jsonObj = JSON.parse(body);
  console.log(jsonObj.$key);
  })
    resp.end('Hello, World!');
});

View solution in original post

4 REPLIES 4

This needs to be handled using express. Please refer to generic node.js POST data handling logic,

For example: http://stackoverflow.com/questions/4295782/how-do-you-extract-post-data-in-node-js

Wondering what is the issue with apigee-access module ?

Not applicable

@Kodandapani, As @Madhan Sadasivam mentioned you can try express but as apigee-access module is not supported on the Edge release you are or you can try the below on your node.js script itself and see if it helps you

@Madhan Sadasivam, do you see any issues with running the below code on edge ? I tried and it works fine .

var svr = http.createServer(function(req, resp) {
   var body = "";
  req.on('data', function (chunk) {
    body += chunk;
  });
  req.on('end', function () {
    console.log('body: ' + body);
    var jsonObj = JSON.parse(body);
  console.log(jsonObj.$key);
  })
    resp.end('Hello, World!');
});

I think this is a duplicate of thread , which is already answered --> http://community.apigee.com/questions/2870/how-to-read-request-payload-in-nodejs.html

Not applicable

Thanks, We are able to read the request payload in node.js