尝试使用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"
}
}
这是从现在开始的。
非常感谢。
答案 0 :(得分:0)
您的 package.json 似乎有拼写错误。您在运行npm install
时出错了吗?
我认为 mangoose 意味着 mongoose 。
此处 node-restful 与您的任何require语句都不匹配。相反,你有restful = require('node-rest-client')