Express: Assigning arrays within req.body object to individual variables
<p>I've been having quite a bit of trouble getting Express and body-parser to read the JSON object that the Angular side of my app is sending over. Based on what I've tried, it seems like my variable assignment syntax is wonky in some way. I've tried quite a few different syntaxes without any success so far, so I'm hoping someone can help me figure out the right way to assign the various bits from the request body into their relevant variables.</p>

<p>Here's some of the troubleshooting I've done so far:</p>

<ul>
<li><p>Verified that the object and the data I want to send is actually being POSTed.</p></li>
<li><p>Verified that Content-Type is "application/json".</p></li>
<li><p>Verified that body-parser is processing the request and req.body is populated with data.</p></li>
<li><p>Tried with and without the explicit setting of "application/json" as the content type without any change in results.</p></li>
</ul>

<p>Here's how $http is sending the data over on the Angular side of things:</p>

<pre><code>.controller ('Ctrl', function($scope, $http) {
 $scope.generateLabel = function(){
        var httpData = [
            {"addressToName": $scope.addressToName},
            {"addressToStreet1": $scope.addressToStreet1},
            {"addressToCity": $scope.addressToCity}, 
            {"addressToState": $scope.addressToState}, 
            {"addressToZip": $scope.addressToZip}, 
            {"addressToEmail": $scope.addressToEmail},  
            {"parcelType": $scope.parcelType}, 
            {"note": $scope.note}, 
            {"sku": $scope.sku}];

 $http({
     method: 'POST',

     url: '/postURL',
     headers: {
       'Content-Type': "application/json"
     },
     data: httpData

    });
};
</code></pre>

<p>...And here's the relevant bit of my Express POST route:</p>

<pre><code>var bodyParser = require('body-parser');
app.use(bodyParser.json({strict: false}));

app.post('/postURL', function(req, res) {

    var addressToName = req.body.addressToName;
    var addressToStreet1 = req.body.addressToStreet1;
    var addressToCity = req.body.addressToCity;
    var addressToState = req.body.addressToState;
    var addressToZip = req.body.addressToZip;
    var addressToCountry = 'US';
    var addressToEmail = req.body.addressToEmail;
}
</code></pre>

<p>Here's what I'm seeing in the node console when I test it. The top messages are from body-parser's debug mode, then it's the raw req.body, then the variables I'm trying to assign them to:</p>

<pre><code>body-parser:json content-type "application/json" +0ms
  body-parser:json content-encoding "identity" +2ms
  body-parser:json read body +1ms
  body-parser:json parse body +13ms
  body-parser:json parse json +1ms
Request body follows:
[ { addressToName: 'My name' },
  { addressToStreet1: 'My address' },
  { addressToCity: 'Anytown' },
  { addressToState: 'OR' },
  { addressToZip: '97504' },
  { addressToEmail: 'My@email.com' },
  { parcelType: '8lb Box' },
  { note: '12314' },
  { sku: '11111' } ]
Variables assigned:
{ addressToName: undefined,
  addressToStreet1: undefined,
  addressToCity: undefined,
  addressToState: undefined,
  addressToZip: undefined,
  addressToCountry: 'US',
  addressToEmail: undefined }
</code></pre>