If you are using the bodyParser
middleware for handling forms, you must be getting this warning message in your Express app.
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Why this warning and how do you resolve it?
bodyParser
is a composite middleware made up of connect.json()
, connect.urlencoded()
, and connect.multipart()
. In Connect 3.0, developers will have to individually include the individual middlewares where required.
However, there is a problem with connect.multipart()
. It will be discontinued because of security concerns. It also is the source for the warning for about connect.limit()
.
You will need to find an alternative for connect.multipart()
. You might come across formidable
, multiparty
, and busboy
in the process. The stream-based busboy
, is the most efficient of them all. However, its interface is a little too complicated for the average Node.js developer; same is the case with connect-busboy
, its interface for Connect / Express.
Introducing Multer, a very user-friendly replacement for connect.multipart()
. Best part, it is written on top of busboy
.
So, how do you use Multer?
Install the package:
$ npm install multer
Load it in your app:
var multer = require('multer');
And then, add it in the middleware stack along with the other form parsing middleware.
app.use(express.json());
app.use(express.urlencoded());
app.use(multer({ dest: './uploads/' }));
connect.json()
handles application/json
connect.urlencoded()
handles application/x-www-form-urlencoded
multer()
handles multipart/form-data
For details about Multer and its options, visit the project page on GitHub.