Austin Austin -4 years ago 73
AngularJS Question

NodeJS Express Req.Body is undefined

I have worked with several solutions posted on stack overflow, and I have yet to find one to work with me so I decided to ask.

Here is my nodejs file: (leaving out irrelevant code)

var express = require('express');
var app = express();
var cors = require('cors');
var bodyParser = require('body-parser');


app.get('/sendEmail', function(req, res) {
var answers = req.body.answers;

and also my POST:

$http.get('http://localhost:5000/sendEmail', {
answers: answer

How come when I console log
I get undefined?

Answer Source

You cannot have a body in a GET request. So change this:'/sendEmail', function(req, res) {
    var answers = req.body.answers;
    // whatever

and this:

$'http://localhost:5000/sendEmail', {
  answers: answer
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download