I am new to nodejs and I am trying to export my custom module but it says function is not defined or is not a function.
I have created a module which contains a function to validate the request body using Joi library. Below is what I have done
validator.js
const Joi = require('joi');
var validateCustomer = function(customer) {
const schema = {
name: Joi.string().min(3).required()
}
return Joi.validate(customer, schema)
}
module.exports.validator = validateCustomer;
customers.js
const validator = require('../myModules/validator');
router.post('/', async (req, res) => {
const {error} = validator(req.body);
if(error) return res.error(404).send(error.details[0].message);
...some code
});
Please help