Post method API in Nodejs

Create the POST method API to insert the document in the MongoDB

Suppose, You have users collection which has three fields
1) _id
2) name
3) email

var MongoClient = require('mongodb').MongoClient;
var express = require('express');
var app = express();'/addUser', function (req, res) {

    MongoClient.connect(url, function (err, db) {


    let req_body=req.body;
    let user_name=(typeof !== 'undefined') ? ("";
    let user_email=(typeof !== 'undefined') ? ("";

    let user_details={

    db.collection("users").insertOne(user_details,function(err, result) {

    if (err){
      res.json({data:result,messages:"some thing went wrong",status:501})

   res.json({data:result,messages:"user add successfully",status:200})



   res.json({data:err,messages:"some thing went wrong",status:501})



Note:- In the above example req.body is used to get the URL body parameters value.