Q:

Cart is not a constructor

I'm learning express.js and trying to learn a shopping cart/session functionality.
Here is my code and my question will be at the bottom/end.
My cart.js
//console.log this function to make sure that the file is required correctly.
sayHello = function () {
    return "Hello in English";
};

var Cart = function Cart(oldCart) {
    this.items = oldCart.items;

    this.add = function (item, id) {
        var storedItem = this.items[id] = { item: item };
        storedItem.qty++
    };
    this.generateArray = function () {
        var arr = [];
        for (var id in this.items) {
            arr.push(this.items[id]);
        }
        return arr;
    };
};

module.exports;

My route has index.js where I list the products and click on any of it to add the product to my cart page, so here is my index.js
 var express = require('express');
var router = express.Router();
var Cart = require('../lib/cart.js');
var db = require('../lib/db.js');
var database = require('../database.js')

var mongoose = require('mongoose');
var Products = mongoose.model('Product');
var User = mongoose.model('User');

mongoose.connect = ('mongodb://localhost/products');

/* GET home page. */
router.get('/', function (req, res) {
     console.log(sayHello());

    Products.find(function (err, products) {
        res.render('index', { title: 'Express 2017 ', products: products });
        console.log(products);
    });
});

router.post('/', function (req, res) {
   // var newUser = new User ({name : req.body.name});
   // newUser.save(function(err, users){
     //   res.render('index', {title: "whatever"})
    //});

     var newProduct = new Products({ name: req.body.name, description: req.body.description, price: req.body.price });
    newProduct.save(function (err, products) {
        res.render('index', { title: "PRODUCTS", products: products });
    });
});

router.get('/cart', function(req, res){

    res.render('cart');

});

//        <<<<<<<<This is where I need help with ....>>>>>>

router.post('/cart', (function (req, res) {
    //The function sayHello() prints Hello In English Correctly.
    console.log(sayHello());
    var productid = req.body.id

    //I get error saying "Cart" is not defined?? Why??
    var cart = new Cart(req.session.cart ? req.session.cart : { items: {}});

    //query the db and return the correct object
    Products.findById({ _id: productid }, function (err, product) {
        //to make sure the db is returning the right item
        console.log(product.name);
f
        //if there is an error...
        if (err) {
            return res.redirect('/');
        }

        //if all is well...then time to add items to the cart.
        //add the product to the cart object and add all this to the session.
        cart.add(product, product.id)
        req.session.cart = cart;

        //Let us see what is in the cart
        console.log(request.session.cart)
        //return the user to the products home page to add more items.
        res.redirect('/');
    });
}));

module.exports = router;

Question: All is working well on the home page (add products to db, display it..etc) and when I hit "Add To Cart" button, I get the error "Cart is not a constructor"...
I'm new to js, so terse, cryptic messages will fly over my head and not going to help, please be generous with your answer and more details the better. 
If you have the time to show me in code how to fix my code will be extremely appreciated  

A:

You did not import the Cart function that you are using.
var cart = new Cart(req.session.cart ? req.session.cart : { items: {}});

You are missing this: module.exports = cart; in your module myCart.js import

