handle post request express code example

Example 1: express get url parameters

app.get('/path/:name', function(req, res) {
  res.send("tagId is set to " + req.params.name);
});

Example 2: express js post request body

const express = require('express')

const 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 3: app.post (req res) get data

const express=require('express');
const app=express();
//accept Post with no midleWare express
app.post("/register/",function(req,res){
    var bodyStr = '';
    req.on("data",function(chunk){
        bodyStr += chunk.toString();
    });
    req.on("end",function(){
        res.send(bodyStr);
    });

});