Hey everyone, I’m having trouble with my AngularJS and Node.js setup. I’m trying to send login info from my Angular app to a Node.js API, but something’s not right.
When I check the request.body on the Node.js side, the data looks weird. It’s like this:
From my experience, the issue lies in how you’re handling the data transmission. On the Angular side, you should indeed use ‘application/json’ as the Content-Type. However, there’s no need to stringify the data manually - Angular’s $http service does this for you. Just adjust your code like this:
For the Node.js part, ensure you’ve set up body-parsing middleware correctly. If you’re using Express 4.16+, you can use the built-in express.json() middleware:
app.use(express.json());
Place this before your route definitions. After these changes, you should be able to access req.body.email and req.body.password without issues. Remember to implement proper error handling and input validation for production use.
yo, i had the same prob. try changing ur content-type to ‘application/json’ in the angular bit. also, make sure ur using express.json() middleware on the node side. that should sort it. good luck mate!