243

Вопрос по node.js, express, json – undefined

Error: User Rate Limit Exceeded

(
        {
        id = 1;
        name = foo;
    },
        {
        id = 2;
        name = bar;
    }
)

Error: User Rate Limit Exceeded

app.post('/', function(request, response) {

    console.log("Got response: " + response.statusCode);

    response.on('data', function(chunk) {
        queryResponse+=chunk;
        console.log('data');
    });

    response.on('end', function(){
        console.log('end');
    });
});

Error: User Rate Limit Exceeded

  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceededconsole.log()Error: User Rate Limit Exceededutil.inspect()Error: User Rate Limit Exceededconsole.log("with request", request.body);

    от
  • Error: User Rate Limit Exceededtext/jsonError: User Rate Limit Exceeded{}Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceededbody

    от
  • Error: User Rate Limit Exceeded

    от
  • request.body.MyKey

    от
  • console.log('request =' + JSON.stringify(request.body))

    от
  • 10

    Error: User Rate Limit Exceeded

            const res_data = JSON.parse(body);
    

  • 192

    Error: User Rate Limit Exceeded

    $ npm install body-parser
    

    var express    = require('express')
    var bodyParser = require('body-parser')
    
    var app = express()
    
    // parse application/json
    app.use(bodyParser.json())
    
    app.use(function (req, res, next) {
      console.log(req.body) // populated!
      next()
    })
    

  • 1

    Error: User Rate Limit Exceeded

    req.body

    headers: {"Content-Type": "application/json"}

  • 360

    Error: User Rate Limit Exceeded

    responserequest.

    responserequest

    Content-Type: application/jsonbodyParserrequest.body

    var express = require('express')
      , app = express.createServer();
    
    app.use(express.bodyParser());
    
    app.post('/', function(request, response){
      console.log(request.body);      // your JSON
      response.send(request.body);    // echo the result back
    });
    
    app.listen(3000);
    

    $ curl -d '{"MyKey":"My Value"}' -H "Content-Type: application/json" http://127.0.0.1:3000/
    {"MyKey":"My Value"}
    

    Updated for Express 4+

    npm install body-parser

    var express = require('express')
      , bodyParser = require('body-parser');
    
    var app = express();
    
    app.use(bodyParser.json());
    
    app.post('/', function(request, response){
      console.log(request.body);      // your JSON
       response.send(request.body);    // echo the result back
    });
    
    app.listen(3000);
    

    Update for Express 4.16+

    express.json()

    var express = require('express');
    
    var app = express();
    
    app.use(express.json());
    
    app.post('/', function(request, response){
      console.log(request.body);      // your JSON
       response.send(request.body);    // echo the result back
    });
    
    app.listen(3000);