I am using a hosted target NodeJS Apigee proxy in my project. The below code is behaving inconsistent, getting request body length as ‘0’ when using valid JSON for the POST method. However, sometimes it’s returning the correct length of the payload. But I am not certain why it’s working that way, I have tested in my npm environment, it worked, also tested in my trial Apigee account, it worked there too.
Can you please post your suggestions.
in index.js
===========
const express = require(‘express’);
const bodyParser = require(‘body-parser’);
const app = express();
app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true}));
require(‘./router/testRouter’)(app);
in testRouter.js
===============
app.route(‘/testAPI/v1/test’).post((req, resp)=> {
var reqBody = req.body;
console.log(“length ===” +Object.keys(reqBody).length);
if(Object.keys(reqBody).length > 0){
//to do
} else{
//to do
}