我正在使用ExpressJS框架构建NodeJS应用程序。
我试图使用monk连接到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
答案 0 :(得分:0)
检查MongoDB端口的运行位置。如果您没有更改默认端口,则应为http://localhost:27017/nodeauth
我认为您的应用正在3000
端口上运行。所以,检查mongod
端口并再次检查。
答案 1 :(得分:0)
省略monk模块的端口号。试试这种方式。
var db = require('monk')('localhost/nodeauth');