javascript - Cannot find module 'expressValidator' - Stack Overflow

Below is a strange error when I try to use expressValidator module in nodejs.Error: Cannot find module

Below is a strange error when I try to use expressValidator module in nodejs.

Error: Cannot find module 'expressValidator'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\wamp\www\learning\nodejs_udemy\node_auth\app.js:5:
24)

Any mistake I made in my app.js?

var expressValidator = require('expressValidator');

// 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
    };
  }
}));

I follow the github usage guide but I still got an error.

Below is a strange error when I try to use expressValidator module in nodejs.

Error: Cannot find module 'expressValidator'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\wamp\www\learning\nodejs_udemy\node_auth\app.js:5:
24)

Any mistake I made in my app.js?

var expressValidator = require('expressValidator');

// 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
    };
  }
}));

I follow the github usage guide but I still got an error.

Share Improve this question asked Oct 4, 2015 at 12:54 Alice XuAlice Xu 5431 gold badge6 silver badges20 bronze badges 1
  • And you have actually installed that? – Roope Commented Oct 4, 2015 at 12:56
Add a ment  | 

2 Answers 2

Reset to default 2

npm modules can't have uppercase letters, the module is called express-validator, not expressValidator. As stated in express-validator's documentation, do:

var expressValidator = require('express-validator');

make sure to

npm i --save express-validator

before you try to use it.

I have similar issue. On my case I did a pull request from git and didn't install all latest packages.

yarn install 

OR

npm install

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745627991a4636926.html

相关推荐

  • javascript - Cannot find module &#39;expressValidator&#39; - Stack Overflow

    Below is a strange error when I try to use expressValidator module in nodejs.Error: Cannot find module

    6小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信