Organizational Research By

Surprising Reserch Topic

how to access the request body when posting using node js and express


how to access the request body when posting using node js and express  using -'javascript,node.js,express'

I have the following Node.js code:

var express = require('express');
var app = express.createServer(express.logger());
app.use(express.bodyParser());

app.post('/', function(request, response) {
    response.write(request.body.user);
    response.end();
});


Now if I POST something like:

curl -d user=Someone -H Accept:application/json --url http://localhost:5000


I get Someone as expected. Now, what if I want to get the full request body? I tried doing response.write(request.body) but Node.js throws an exception saying "first argument must be a string or Buffer" then goes to an "infinite loop" with an exception that says "Can't set headers after they are sent."; this also true even if I did var reqBody = request.body; and then writing response.write(reqBody).

What's the issue here?

Also, can I just get the raw request without using express.bodyParser()?
    
asked Sep 22, 2015 by kotmus2002
0 votes
6 views



Related Hot Questions



Government Jobs Opening


...