MEAN - 节点 - 猫鼬 - 错误

时间:2016-08-05 06:02:01

标签: mongodb mean

尝试使用MEAN创建简单的API。

我正在关注youtube链接作为指南

https://www.youtube.com/watch?v=MMOIr_VwwAk

在3000上设置端口。当尝试运行它时,抛出错误,如fallows

**mongoose.connect('mongodb://localhost/restful');
        ^
TypeError: Cannot read property 'connect' of undefined**

server.js

 var express = require ('express'),
    restful = require('node-rest-client'),
    mongoose = restful.mongoose;

var app = express();
app.get(function(){
    app.use(express.bodyParser());
    app.use(express.methodOverride());
});

mongoose.connect('mongodb://localhost/restful');

var ProductSchema = mongoose.Schema({
    name : String,
    sku: String,
    price:Number
});

var Products =restful.model('products',ProductSchema);
Products.methods(['get','put','post','delete']);
Products.register(app,'/api/products');
app.listen(3000);
console.log("am running on port 3000");

的package.json

   {
  "name": "restful",
  "main": "server.js",
  "dependencies": {
    "express": "^4.14.0",
    "mangoose": "latest",
    "node-restful": "latest"
  }
}

这是从现在开始的。

非常感谢。

1 个答案:

答案 0 :(得分:0)

您的 package.json 似乎有拼写错误。您在运行npm install时出错了吗?

我认为 mangoose 意味着 mongoose 。 此处 node-restful 与您的任何require语句都不匹配。相反,你有restful = require('node-rest-client')