Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Most middleware (like json) is no longer bundled with Express and must be installed separately. Please see

i move my source window to ubuntu :

Error: Most middleware (like json) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.

this is my source thank you

var http = require('http'); var fs = require('fs'); var express = require('express'); var mysql = require('mysql'); var ejs = require('ejs');  var app = express(); app.use(express.bodyParser()); app.use(app.router); 
like image 986
incleaf Avatar asked Apr 12 '14 17:04

incleaf


2 Answers

There are a number of changes with express 4.x. Like the error says, all of the middleware has been removed.

Update your package.json to include the "new" packages, a basic list can be found here and a full list here

Using your code from above, you would just need the following:

// package.json {   "dependencies":   {     "express":"*",     "body-parser":"*"   } } 

Then update your source to reflect the new changes:

// app.js var http = require('http'),     fs = require('fs'),     express = require('express'),     bodyParser = require('body-parser'),     mysql = require('mysql'),     ejs = require('ejs');  var app = express(); app.use(bodyParser.urlencoded({     extended: true })); app.use(bodyParser.json()); 

Note that app.use(app.router) has been removed as well.

like image 135
kmchugh12 Avatar answered Sep 19 '22 16:09

kmchugh12


if some middleware is not bundled with express then dont use express keyword while using them..

instead of this -

app.use(express.bodyParser()); 

write this -

app.use(bodyParser()); 
like image 22
Partha Roy Avatar answered Sep 22 '22 16:09

Partha Roy