Create SchemaValidator
    const Joi = require('joi');

const options = {
abortEarly: false, // include all errors
allowUnknown: true, // ignore unknown props
stripUnknown: true // remove unknown props
};

class UserSchemaValidator {


validateCreateUserSchema = async function (req,res,next){


const schema = Joi.object({
name: Joi.string().required(),
email: Joi.string().email().required(),
password: Joi.string().min(6).required(),
role: Joi.string().valid('ADMIN', 'USER').required()
});

try{
let result = await schema.validateAsync(req.body, options);
console.log("Result:", result);
next();
}
catch(error){
let errorMessages = error.details.map(x=> ({ field: x.path[0], message: x.message}));
console.error(JSON.stringify(errorMessages));
let result = { status: 400, errors: errorMessages};
res.status(400).json(result);
}
}
}

exports.UserSchemaValidator = UserSchemaValidator;
Use Schema Validator in router.js
    const express = require('express');
const router = express.Router();

const {UserSchemaValidator} = require('./user.schema.validator');

// routes
const userSchemaValidator = new UserSchemaValidator();
router.post('/api/users/', userSchemaValidator.validateCreateUserSchema, createUser);

function createUser(req,res){
let user = req.body;
res.status(200).json(user);
}


module.exports = router;
Run the server - app.js
    const express = require('express');
const router = require('./router');
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

app.use('/', router);
const port = 3000
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`)
})
Test the API in POSTMAN Tool
     { name:"Naresh", email:"", password:"1", role:"USER"}
Response Error Messages
    {
"status": 400,
"errors": [
{
"field": "email",
"message": "\"email\" is not allowed to be empty"
},
{
"field": "password",
"message": "\"password\" length must be at least 6 characters long"
}
]
}