Quoting only the important parts of the code.
This is my server.js
in the node backend server
//routes
const userapi = require('./api/routes/user');
//models
require('./api/models/userModel');
//use routes
userapi(app);
on my userapi
which is my routes I call my userController
(function () {
'use strict';
module.exports = function (app) {
var userCtrl = require('../controllers/userCtrl');
app.post('/api/validate_user', function(req, res, next){
userCtrl.validate_user(req, res);
});
}
})();
and this is my userController code. In the future, i will write a code that will handle all the transaction from my MongoDB.
'use strict';
var mongoose = require('mongoose'),
model = mongoose.model('users'),
brcpyt = require('bcrypt');
module.exports = function() {
return {
validate_user: function(req, res) {
console.log('here');
}
}
};
The problem is, everytime I make a http request from my frontend. I get an error that says userCtrl.validate_user
is not a function. My frontend can access the endpoints of '/api/validate_user'
and the var userCtrl = require('../controllers/userCtrl')
is a correct file path, but everytime that I type userCtrl
to my routes it does not give me function validate_user