express use json code example

Example 1: urlencoded json express

var express = require('express')

var app = express()

app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded

app.post('/profile', function (req, res, next) {
  console.log(req.body)
  res.json(req.body)
})

Example 2: http header express

app.get('/', (req, res) => {
  req.header('User-Agent')
})
// Use the Request.header() method to access
//one individual request header’s value