I would to access to a method from another module calling that method inside a route. with this notation of module.exports does't work beacause in my console I get an error like getProducts is not a function
const express = require('express');
const router = express.Router();
const path = require('path');
const productsController = require('../controller/productsController')
const productModel = require('../models/productModel');
// send html file
router.get('/', function (req, res) {
res.sendFile(path.join(__dirname, '../public/esercitazione-AJAX.html'));
});
//to /getProducts call a method from productsController
router.get('/getProducts', function (req, res){
productsController.productsController()
});
module.exports = router;
this is my module
//productsController.js
const productModel = require('../models/productModel');
var productsController = function() {
console.log('productsController')
var getProducts = function(req,res,callback) {
var callback = function(result) {
res.send(result);
}
productModel.getProducts(req, res, callback);
}
}
module.exports = new productsController();