Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8291279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:04:49+00:00 2026-06-08T13:04:49+00:00

I have the following Node.js code: var express = require(‘express’); var app = express.createServer(express.logger());

  • 0

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()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:04:50+00:00Added an answer on June 8, 2026 at 1:04 pm

    Express 4.0 and above:

    $ npm install --save body-parser

    And then in your node app:

    const bodyParser = require('body-parser');
    app.use(bodyParser);
    

    Express 3.0 and below:

    Try passing this in your cURL call:

    --header "Content-Type: application/json"

    and making sure your data is in JSON format:

    {"user":"someone"}

    Also, you can use console.dir in your node.js code to see the data inside the object as in the following example:

    var express = require('express');
    var app = express.createServer();
    
    app.use(express.bodyParser());
    
    app.post('/', function(req, res){
        console.dir(req.body);
        res.send("test");
    }); 
    
    app.listen(3000);
    

    This other question might also help: How to receive JSON in express node.js POST request?

    If you don’t want to use the bodyParser check out this other question: https://stackoverflow.com/a/9920700/446681

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following node.js server-side code: var app = require('http').createServer(handler) , io =
We have the following example in node.js var http = require('http'); http.createServer(function(request, response) {
i have the following code: var net = require('net'); var server = net.createServer(function (stream)
On my node.js server I have the following code: //Generate a token var token
I have the following Node.js directory structure. |--app/ |--app.js |--routers/ |--index.js/ |--models/ |--schemas.js |--post.js
I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
Currently I have the following code, working with Node.js, socket.io and Redis: var io
in socket.io 0.6, i have following example code: var io = require('/usr/lib/node_modules/socket.io'); var server
I have the following simple http server using Node.js: var http = require('http'); var
I have following code. var mysql = require('mysql'); var connection = mysql.createConnection({ host :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.