simonplend / express-json-validator-middleware

Express middleware for validating requests against JSON schema

Home Page:https://npm.im/express-json-validator-middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when starting an express server

AarRidho opened this issue · comments

Hi! I would like to ask about this Error i'm currently having on my project.

const validateFunctions = Object.keys(options).map(function (requestProperty) {
                                                      ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Validator.validate (C:\xampp\htdocs\siakad-new\node_modules\express-json-validator-middleware\src\index.js:24:42)
    at Object.<anonymous> (C:\xampp\htdocs\siakad-new\routes\users_route.js:25:54)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
[nodemon] app crashed - waiting for file changes before starting...

I tried to do exactly the same approach like in the README, but still got this Error.

const { validate } = require('../config/validator');

router.get('/:id', validate({ params: UsersSchema.getUsersById.params }), validate(UsersSchema.getUserById), UsersController.getUserById);

Am i missing something here actually?

Any replies would be helpful.

I'm sorry, this was my fault actually...

i called the validate() function 2x on the route

Thanks for this great library