最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

ExpressValidator不是函数

IT培训 admin 5浏览 0评论

ExpressValidator不是函数

  • 我正在使用mongodb(v4.2.0),node.js(v12.11.1)构建Web登录功能,并且正在使用快速框架
  • 我已经在package.json中安装了express-validator(v6.2.0)
  • 在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'之后,我得到:

    > [email protected] 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! [email protected] start: `node ./bin/www`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the [email protected] start script.

我该如何解决?

回答如下:

以下是快速验证器legacy API的文档。

ExpressValidator不是函数

  • 我正在使用mongodb(v4.2.0),node.js(v12.11.1)构建Web登录功能,并且正在使用快速框架
  • 我已经在package.json中安装了express-validator(v6.2.0)
  • 在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'之后,我得到:

    > [email protected] 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! [email protected] start: `node ./bin/www`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the [email protected] start script.

我该如何解决?

回答如下:

以下是快速验证器legacy API的文档。

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论