【问题标题】:Nodejs: npm throwing error when using monkNodejs:使用僧侣时npm抛出错误
【发布时间】:2016-03-31 10:22:44
【问题描述】:

我正在使用 ExpressJS 框架构建一个 NodeJS 应用程序。

我正在尝试使用和尚连接到 MongoDB

var monk = require('monk');
var db = monk('localhost:3000/nodeauth');

当我执行 npm start 时,我收到以下错误:

npm start

> jsblog@0.0.0 start /home/bytegeek/Codes/Expressprojects/jsblog
> node ./bin/www

/home/bytegeek/Codes/Expressprojects/jsblog/node_modules/mongoskin/lib/utils.js:33
  var skinClassName = 'Skin' + NativeClass.name;
                                      ^

TypeError: Cannot read property 'name' of undefined
    at makeSkinClass (/home/bytegeek/Codes/Expressprojects/jsblog/node_modules/mongoskin/lib/utils.js:33:43)
     at Object.<anonymous> (/home/bytegeek/Codes/Expressprojects/jsblog/node_modules/mongoskin/lib/grid.js:6:35)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/home/bytegeek/Codes/Expressprojects/jsblog/node_modules/mongoskin/lib/db.js:22:16)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/home/bytegeek/Codes/Expressprojects/jsblog/node_modules/mongoskin/lib/mongo_client.js:5:14)

npm ERR! Linux 4.2.0-34-generic
npm ERR! argv "/opt/node-v5.7.1-linux-x64/bin/node" "/opt/node-v5.7.1-linux-x64/bin/npm" "start"
npm ERR! node v5.7.1
npm ERR! npm  v3.6.0
npm ERR! code ELIFECYCLE
npm ERR! jsblog@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the jsblog@0.0.0 start script 'node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the jsblog package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs jsblog
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls jsblog
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/bytegeek/Codes/Expressprojects/jsblog/npm-debug.log

我已经有一个 MongoDB 数据库nodeauth 并且里面也有一些内容。 mongod 服务也在运行中。

P.S:如果我删除上面两行代码并执行npm start,没有错误,我可以在localhost:3000看到快速欢迎页面

【问题讨论】:

    标签: node.js mongodb express ubuntu-14.04


    【解决方案1】:

    检查运行它的 MongoDB 端口。如果你没有改变默认端口,它应该是http://localhost:27017/nodeauth

    我认为您的应用正在3000 端口上运行。所以,检查mongod 端口并再次检查。

    【讨论】:

    • mongodb 在 27017 上运行。但 localhost:27017/nodeauth 没有帮助。仍然出现相同的错误。是的,应用程序正在3000 端口上运行。
    【解决方案2】:

    省略和尚模块的端口号。试试这个方法。

    var db = require('monk')('localhost/nodeauth');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-30
      • 1970-01-01
      • 2019-06-25
      • 2016-07-20
      • 1970-01-01
      • 2014-02-17
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多