how to print the data from post request on console

前端 未结 6 1010
忘掉有多难
忘掉有多难 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 17:02

    Instead of query:

    var keyName=request.query.Key;
       console.log(keyName);
    

    use body:

    var keyName1=request.body.key;
    console.log(keyName1);
    

    Code:

    var express = require('express')
     , async = require('async')
     , http = require('http');
    
    var app = express();
    
    app.set('port', process.env.PORT || 7002);
    
    app.use(express.static(__dirname + '/public/images'));
    
    app.use(express.bodyParser());
    
    app.post('/Details/',function(request,response,next){
    
       var keyName1=request.body.key;
       console.log(keyName1);
    } );
    
    
    http.createServer(app).listen(app.get('port'), function(){
     console.log('Express server listening on port ' + app.get('port'));
    });
    

提交回复
热议问题