无法启动节点服务器,问题与MongoDB数据库?

我试图按照这个教程 ,我不能运行节点服务器,因为这个错误:

TypeError:无法在makeSkinClass中读取未定义的属性“名称”

这是我的path:

echo $ PATH / usr / local / mysql / bin:/ mongodb / bin:Users / Empon / npm / bin:/ usr / local / bin:/ usr / bin:/ bin:/ usr / sbin:/ sbin:/ opt / X11 / bin中:在/ usr /本地/ git的/ bin中

我发现-g在我的terminal中永远不会工作,所以我试图永久地将path添加到PATH中,我将mongodb添加到bashrc和bash_profile中。

然后我做了npm install -g mongodb ,我有这个:

mongodb-core@1.2.32需要kerberos@~0.0,但没有安装。

所以我加了npm install --save kerberos mongodb ,结果是:

npm WARN skippingAction模块位于符号链接模块内部:不运行remove bson@0.4.21 node_modules / mongodb / node_modules / bson npm WARN skippingAction模块位于符号链接模块中:未运行remove core-util-is@1.0.2

现在,在我的节点项目中,我做了: node bin/www来启动服务器(我尝试了节点app.js,在configuration文件中使用了“app.js”,但它没有工作,所以我让./bin/www ),url是: http://localhost:3000/api/videos

你知道什么是错的吗?


编辑:我得到它的工作,与这些操作:安装一个老版本的mongodb和改变configuration文件中的一行:

mongodb是否只运行MongoDB版本1.4以上?

找不到模块'../build/Release/bson'] code:'MODULE_NOT_FOUND'} js-bson:无法加载c ++ bson扩展,使用纯JS版本

我几乎在那里,该端口的url工作正常( http:// localhost:3000 / ),但不是一个为MongoDB( http:// localhost:3000 / api / videos ),错误是:

错误:找不到/Applications/MAMP/htdocs/workspace/Vidzy/app.js:32:13在Layer.handle [as handle_request](/ Applications / MAMP / htdocs / workspace / Vidzy / node_modules / express / lib / router /layer.js:95:5)在trim_prefix(/Applications/MAMP/htdocs/workspace/Vidzy/node_modules/express/lib/router/index.js:312:13)

而我的代码是:

 //in routes/video.js var express = require('express'); var router = express.Router(); var monk = require('monk'); var db = monk('localhost:27017/vidzy'); router.get('/', function(req, res){ var collection = db.get('videos'); collection.find({}, function(err, videos){ if (err) throw err; res.json(videos); }); }); module.exports = router; //in app.js // catch 404 and forward to error handler app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); }); 

terminal连接到mongoDB:

I NETWORK [initandlisten]正在等待端口27017上的连接

会有人知道我为什么得到一个404,以及如何debugging?

我解决了我的问题:mongodb的版本不正确,mongoskin的版本也是如此。 我不知道为什么错误发生,但用mongodb 1.4和mongoskin 1.3设置项目工作正常。

npm install mongoskin@1.3.20 --save

$ npm install mongodb@~1.4 --save

来源: 运行mongoskin只与mongodb版本1.4和更旧?


如果debugging文件出现问题,请进行以下更改:

replace: bson = require('../build/Release/bson');

用: bson = require('../browser_build/bson');

在:

npm module mongodb ..node_modules \ mongodb \ node_modules \ bson \ ext \ index.js

源: 找不到模块'../build/Release/bson']代码:'MODULE_NOT_FOUND'} js-bson:无法加载c ++ bson扩展,使用纯JS版本

根据教程,你不应该用npm安装mongodb。 看起来你正在使用Linux,所以按照这个链接上的一个教程:

https://docs.mongodb.org/manual/administration/install-on-linux/

检查你的package.json的mongodb(如果它在那里,删除它)应该工作