My app.component.ts contains
login() {
var user = `{ email: ${this.email}, password: ${this.password} }`
const headers = new HttpHeaders()
.set('Authorization', 'my-auth-token')
.set('Content-Type', 'application/json');
this.http.post('http://localhost:3000/signin', user, {
headers: headers
}).subscribe(data => {
});
console.log(`email: ${this.email} password: ${this.password}`)
}
When trying to get the data in node I get
error: SyntaxError: Unexpected token e in JSON at position 2
I am using
req.body
to get the data. What is the correct way to parse the JSON data? Also wanted to know if this is the correct way to pass form data from angular to node?
userlike this :JSON.stringify(user)userin console.log what you get there