sending JSON to Express

254
March 16, 2018, at 9:32 PM

I read many posts about how to send json to express via post but none worked or fixed my issue.

my issue is that when reading req.body where req is the request object i get an output like this : { '{"z":"z"}': '' } for this obejct i sent {z:"z"}

That is not expected and not any kind of behavior is saw before.

this si the angular httpClient request :

return new Promise((res,rej)=>{
        this.http.post("http://localhost:3000/Auth/Login",{z:"z"},{headers:new HttpHeaders('Content-Type:application/x-www-form-urlencoded')})
            .toPromise()
              .then(
              response =>{
               res(response)
              }
              ).catch(
                  err=>{
                      rej(err)
                  }
              )
    })

This is the server code :

router.route('/Login').all(function (req, res, next) {
    next();
}).post(function(req, res, next) {
    console.log(req.body);})

what i want is to get the same object i sent that is it.

Help !

Rent Charter Buses Company
READ ALSO
How to connect to a node server from a button press?

How to connect to a node server from a button press?

Can I connect to a nodejs server with socketio from a button press? I got my page for example file:///home

247
Using MongoDB ObjectIds with lodash

Using MongoDB ObjectIds with lodash

I keep running into trouble when working with ObjectIds and lodashSay I have two arrays of objects I want to use lodash _

196