take data in the method post

Asked

Viewed 234 times

0

I’m sending an angular object, but I’m not getting the data on the express Node

method sent with angular.

this.appService.getcheckout(this.post()).subscribe(checkout => {
      this.log = this.log+ checkout
    });
post(){
    return [
      {
          "path": this.path,
          "branchDev": this.branch
      }
    ];
  }

attempt on express

var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({
    extended: false
}));


app.post('/checkout', cors(),function (req, res) {
    console.log(req.body);
    console.log(req.body.path);
)};

console

user@bitter:/var/www/html/gitrun$ node express.js 
[ { path: '/var/www/html/gitrun', branchDev: ' git-1' } ]
undefined

1 answer

1


You are sending an array to Node.js. Change the Angular apra code to send without being array.

this.appService.getcheckout(this.post()).subscribe(checkout => {
      this.log = this.log+ checkout
    });
post(){
    return 
      {
          "path": this.path,
          "branchDev": this.branch
      };
  }

You could read like this:

console.log(req.body[0].path);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.