Below i have given a code for a test REST API.
// Imports
var express=require("express")
, mongoose=require("mongoose")
, bodyParser= require('body-parser')
, bodyParser = require("body-parser");
const { Int32 } = require("bson");
// Constants
const app = express()
const PORT=4002
// Our Schema
var data={
value: Number
}
// Create a model
const dataModel=mongoose.model('dataCollection',mongoose.Schema(data))
// Making connection with database
mongoose.Promise= global.Promise;
mongoose.connect('mongodb://localhost/testdb', {
useNewUrlParser:true,
useUnifiedTopology:true
})
// Create the controller to save data
function postData(req,res){
console.log(req.body)
let newData = new dataModel(req.body)
newData.save((err,resp)=>{
if(err) console.log(err)
else res.json(resp)
})
}
// body-parser setup
app.use(bodyParser.urlencoded({extended:true}));
// express set root page
app.get('/',(req,res)=> res.send("ROOT PAGE"));
// Set Route for our post request
app.route('/app')
.get((req,res)=>res.send("Nothing here"))
.post(postData);
// start listening on server
app.listen(PORT,()=>console.log(`Your application is running on Port: ${PORT}`));
Below is the test of POST request test of this code:

Below is the output produced by Node js:
node ./test.js
Your application is running on Port: 4002
{ userName: 'Adnan', UserID: '1', password: '123' }
The object below Port number in this output is produced by console.log(req.body) in postData but the response returned as seen in the screenshot above is an empty object which is stored in the collection instead of actual data.