NodeJS and Express : How to print all the parameters passed in GET and POST request NodeJS and Express : How to print all the parameters passed in GET and POST request express express

NodeJS and Express : How to print all the parameters passed in GET and POST request


So POST parameters arrive in the HTTP request body, and this is handled as a stream of data chunks by node.js. So the first thing you must do is make sure you assemble the stream of chunks into a complete piece of data. Then you may want to parse it as either url encoded or JSON if that's what it is. The standard middleware for this is body-parser. You set it up like they say in the README:

const express    = require('express')const bodyParser = require('body-parser')const app = express()// parse application/x-www-form-urlencodedapp.use(bodyParser.urlencoded({ extended: false }))// parse application/jsonapp.use(bodyParser.json())// parse application/vnd.api+json as jsonapp.use(bodyParser.json({ type: 'application/vnd.api+json' }))app.use(function (req, res, next) {  console.log(req.body) // populated!  next()})