express-validator doesn't do anything

Jaruzel

I'm trying to use express-validator, but none of it's functions work. I'm not getting any errors either.

Example:

const check = require('express-validator/check').check;

router.post('/register', check('someRandomName').exists(), (req, res) => userController.register(req, res));

express-validator always allows it, even if I don't have someRandomName in the req.

I also tried using body instead of check, but the result was the same.

feiiiiii

The check returns a validation chain which you suppose to validate result in your req after it using validationResult, so something like this:

const {check , validationResult}  = require('express-validator/check');

router.post('/register', check('someRandomName').exists(), (req, res) => {
       var err = validationResult(req);
       if (!err.isEmpty()) {
           console.log(err.mapped())
           // you stop here 
       } else {
           // you pass req and res on to your controller
       }
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Grunt Smoosher doesn't do anything

分類Dev

btrfs filesystem resize doesn't do anything

分類Dev

Grunt + Babel successfully runs but doesn't do anything

分類Dev

Why doesn't mongoose's .find({}) method do anything at all?

分類Dev

Python script converted to exe doesn´t do anything

分類Dev

Why booting into rescue mode menu doesn't do anything?

分類Dev

Logitech MX Anywhere 2 mouse pairs but doesn't do anything

分類Dev

Logitech MX Anywhere 2 mouse pairs but doesn't do anything

分類Dev

postgresql trigger with dblink doesn't return anything

分類Dev

AlamoFire doesn't appear to be doing anything

分類Dev

Array doesn't print anything on executing code

分類Dev

PHP SimpleXML doesn't output anything

分類Dev

Collectionview doesn't show anything during runtime

分類Dev

Why doesn't ZIP Compression compress anything?

分類Dev

Can't validate user input by using Express-validator

分類Dev

the android device is connected to the wamp server but doesn't show anything in listview

分類Dev

"dnvm" command inside Package Console Manager doesn't show anything

分類Dev

Angular 2 Firebase Observable to promise doesn't return anything

分類Dev

Extending tsconfig.json file doesn't seem to extend anything

分類Dev

VS Code Debugger - Felix Becker - Debugger doesn't hit anything

分類Dev

Why doesn't anything in my if-else work?

分類Dev

logstash agent doesn't output anything in verbose mode

分類Dev

express-validator Breakvalidatorchain

分類Dev

npm「validator」と「express-validator」

分類Dev

Express doesn't support data-method?

分類Dev

express-validator 4 not working

分類Dev

errors generated by express validator with node express

分類Dev

Why I am able to override Equals method if my class doesn't inherit from anything?

分類Dev

JavaScript aws-sdk S3 deleteObject(s) succedes but doesn't actually delete anything

Related 関連記事

  1. 1

    Grunt Smoosher doesn't do anything

  2. 2

    btrfs filesystem resize doesn't do anything

  3. 3

    Grunt + Babel successfully runs but doesn't do anything

  4. 4

    Why doesn't mongoose's .find({}) method do anything at all?

  5. 5

    Python script converted to exe doesn´t do anything

  6. 6

    Why booting into rescue mode menu doesn't do anything?

  7. 7

    Logitech MX Anywhere 2 mouse pairs but doesn't do anything

  8. 8

    Logitech MX Anywhere 2 mouse pairs but doesn't do anything

  9. 9

    postgresql trigger with dblink doesn't return anything

  10. 10

    AlamoFire doesn't appear to be doing anything

  11. 11

    Array doesn't print anything on executing code

  12. 12

    PHP SimpleXML doesn't output anything

  13. 13

    Collectionview doesn't show anything during runtime

  14. 14

    Why doesn't ZIP Compression compress anything?

  15. 15

    Can't validate user input by using Express-validator

  16. 16

    the android device is connected to the wamp server but doesn't show anything in listview

  17. 17

    "dnvm" command inside Package Console Manager doesn't show anything

  18. 18

    Angular 2 Firebase Observable to promise doesn't return anything

  19. 19

    Extending tsconfig.json file doesn't seem to extend anything

  20. 20

    VS Code Debugger - Felix Becker - Debugger doesn't hit anything

  21. 21

    Why doesn't anything in my if-else work?

  22. 22

    logstash agent doesn't output anything in verbose mode

  23. 23

    express-validator Breakvalidatorchain

  24. 24

    npm「validator」と「express-validator」

  25. 25

    Express doesn't support data-method?

  26. 26

    express-validator 4 not working

  27. 27

    errors generated by express validator with node express

  28. 28

    Why I am able to override Equals method if my class doesn't inherit from anything?

  29. 29

    JavaScript aws-sdk S3 deleteObject(s) succedes but doesn't actually delete anything

ホットタグ

アーカイブ