skip to Main Content

Javascript – Joi validation not working correctly Nodejs

I am trying to validate a schema. its not very complex. below is my code Joi.object({ mobile: Joi.string() .label('mobile') .pattern(/^(+)[1-9]d{7,14}$/) .messages({ 'string.pattern.base': 'Invalid mobile number', }), email: Joi.string() .email({ tlds: { allow: false } }) .label('email') .messages({ 'string.email': 'Invalid email…

VIEW QUESTION

Javascript – Cannot read properties of null (reading 'collection'), this error is coming when submitting form. Unable to store data in database

in connection.js const mongoClient=require('mongodb').MongoClient const state={ db:null } module.exports.connect=function (done){ const url='mongodb://localhost:27017/' const dbname='shopping' mongoClient.connect(url,(err,data)=>{ if(err) return done(err) state.db=data.db(dbname) }) done() } module.exports.get=()=>state.db in product-helpers var db=require('../config/connection') module.exports={ addProduct:(product,callback)=>{ console.log(product) db.get().collection('product').insertOne(product).then((data)=>{ console.log(data); callback(true) }) } } I am unable to…

VIEW QUESTION
Back To Top
Search