I'm sending a POST in angularjs like so:
$http.post("/mypath", { data: "foobar" })
And in nodejs (expressjs) I'm trying to pick it up like so:
app.post "/mypath", (req, res) ->
console.log "req.body: ", req.body
res.end()
I've tried various different incarnations (body: "foobar", etc), but I keep getting req.body: undefined
Is there a simple way to read the payload in node/express?
To get data from a POST in Node, you need to use a body Parser. eg:
var bodyParser = require('body-parser');
//use bodyParser() to let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With