Zanmate Zanmate - 5 months ago 11
Node.js Question

Error while making a connection in Node.js

I get the following message whenever I run the code


throw new Error('Most middleware (like ' + name + ') is no longer
bundled with express and must be installed separately ^ Error: Most
middleware(like BodyParser) is no longer bundled with Express and must
be installed separately.


My code is as following:

var express = require("express"),
restful = require("node-restful");
mongoose = restful.mongoose;

var app = express();
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("Server is running at port 3000")


I've installed npm body parser and npm method override separately but it still gives me the error message.

Answer

It seems to me that you do not require body-parser.

You should have something like var bodyParser = require('body-parser'); and then use it like app.use(bodyParser.json());if you want the json parser for example.

Since it is no longer in express, you cannot require it and use it through express

Comments