text: // product.route.js
  
  const express = require('express');
  const app = express();
  const productRoutes = express.Router();
  
  // Require Product model in our routes module
  let Product = require('../models/Product');
  
  // Defined store route
  productRoutes.route('/add').post(function (req, res) {
    let product = new Product(req.body);
    product.save()
      .then(product => {
        res.status(200).json({'Product': 'Product has been added successfully'});
      })
      .catch(err => {
      res.status(400).send("unable to save to database");
      });
  });
  
  // Defined get data(index or listing) route
  productRoutes.route('/').get(function (req, res) {
    Product.find(function (err, products){
      if(err){
        console.log(err);
      }
      else {
        res.json(products);
      }
    });
  });
  
  // Defined edit route
  productRoutes.route('/edit/:id').get(function (req, res) {
    let id = req.params.id;
    Product.findById(id, function (err, product){
        res.json(product);
    });
  });
  
  //  Defined update route
  productRoutes.route('/update/:id').post(function (req, res) {
    Product.findById(req.params.id, function(err, product) {
      if (!product)
        res.status(404).send("Record not found");
      else {
        product.Barcode = req.body.Barcode;
        product.ProductCategory = req.body.ProductCategory;
        product.Name = req.body.Name;
        product.Distributor = req.body.Distributor;
       
        product.GST=req.body.GST;
        product.MRP=req.body.MRP;
        product.ExpiryDate=req.body.ExpiryDate;
       
       
        product.save().then(product => {
            res.json('Update complete');
        })
        .catch(err => {
              res.status(400).send("unable to update the database");
        });
      }
    });
  });
  
  // Defined delete | remove | destroy route
  productRoutes.route('/delete/:id').get(function (req, res) {
      Product.findByIdAndRemove({_id: req.params.id}, function(err, product){
          if(err) res.json(err);
          else res.json('Successfully removed');
      });
  });
  
  module.exports = productRoutes;