ExpressValidator不是函数

时间:2019-10-12 17:27:41

标签: node.js json mongodb express express-validator

  • 我正在使用mongodb和node.js构建Web登录功能。我正在使用一个表达框架
  • 我已经在package.json中安装了express-validator
  • 在app.js中,有关expressValidator的行显示为:
var expressValidator = require('express-validator');
app.use(expressValidator({
    errorFormatter: function(param, msg, value){
    var namespace = param.split('.'),
    root = namespace.shift(),
    formParam = root;
    while(namespace.length){formParam += '[' + namespace.shift() + ']';}
    return{param: formParam, msg: msg, value: value};
    }
}));

在终端上运行“ npm start”后,我得到:

    > nodeauthorization@0.0.0 start /Users/username/Desktop/nodeauthorization
    > node ./bin/www

    /Users/username/Desktop/nodeauthorization/app.js:44
    app.use(expressValidator({
            ^

    TypeError: expressValidator is not a function
    at Object.<anonymous>(/Users/username/Desktop/nodeauthorization/app.js:44:9)
    at Module._compile (internal/modules/cjs/loader.js:945:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Module.require (internal/modules/cjs/loader.js:838:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/Users/username/Desktop/nodeauthorization/bin/www:7:11)
    at Module._compile (internal/modules/cjs/loader.js:945:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
    at internal/main/run_main_module.js:17:11
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! nodeauthorization@0.0.0 start: `node ./bin/www`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the nodeauthorization@0.0.0 start script.

我该如何解决?

1 个答案:

答案 0 :(得分:0)

以下是Express Validator的legacy API的文档。

可以在here处找到API更改过的最新文档

这是包裹的官方GitHub