nodeexpress handle post request code example
Example 1: node js express url parameters
app.get('/api/:version', function(req, res) {
res.send(req.params.version);
});
Example 2: app.post (req res) get data
const express=require('express');
const app=express();
app.post("/register/",function(req,res){
var bodyStr = '';
req.on("data",function(chunk){
bodyStr += chunk.toString();
});
req.on("end",function(){
res.send(bodyStr);
});
});
Example 3: express route parameters
app.get('/users/:userId/books/:bookId', function (req, res) {
res.send(req.params)
})