Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connect: multipart: use parser (multiparty, busboy, formidable)

Tags:

node.js

I'm trying to build my first node.js application, but, running using node server.js I get the following error message :

connect: multipart: use parser (multiparty, busboy, formidable) directly connect: limit: Restrict request size at location of read

as shown by this screenshot:

enter image description here

snippet of code in which I'm using connect:

var connect = require('connect'),
    express = require('express');

var app = express();
app.use(connect.cookieParser())
    .use(connect.session({secret: 'app_1'}))
    .use(connect.bodyParser())

How to fix this, please? Thanks a lot!

like image 586
Lucie kulza Avatar asked Jun 03 '14 10:06

Lucie kulza


2 Answers

connect is deprecated since express.js version 4. Try installing the middleware (1, 2, 3) separately like this:

$ npm install cookie-parser --save
$ npm install body-parser --save
$ npm install cookie-session --save

And in your code:

var express = require('express');
var app = express();

var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var cookieSession = require('cookie-session');

app.use(cookieParser());
app.use(bodyParser());
app.use(cookieSession({secret: 'app_1'}));
like image 108
neelsg Avatar answered Sep 19 '22 04:09

neelsg


replace

.use(connect.bodyParser())

into

.use(express.urlencoded()); .use(express.json());

source https://github.com/visionmedia/express/issues/1793

edit: full code

var connect = require('connect'),
express = require('express');

var app = express();
app.use(connect.cookieParser()) // i use express.cookieParser, but connect.cookieParser should also work 
  .use(express.urlencoded());
  .use(express.json());

like image 43
Simone Sanfratello Avatar answered Sep 21 '22 04:09

Simone Sanfratello