how to print the data from post request on console

前端 未结 6 1008
忘掉有多难
忘掉有多难 2021-02-18 16:07

I am trying to print the post data on my console


app.js

var express = require(\'express\')
 , http = require(\'http\');

var app         


        
6条回答
  •  北荒
    北荒 (楼主)
    2021-02-18 16:59

    An update on using the middleware, body-parser, for later versions of Express: Using app.use(express.bodyParser()) will report an error such as: Error: Most middleware (like bodyParser) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.

    This can be addressed by first installing the body-parser middleware:

    npm install body-parser
    

    then write code such as:

    var bodyParser = require('body-parser');
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    

    and then accessing the body of the request object, for example, console.log(req.body)

提交回复
热议问题