75

I'm a node.js developer who creates web apps using express.js. By now, my problem is:

Whenever I create an app on my computer, npm install its stuff and run it (with node app.js and nodemon) I get this message in the console:

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
Express server listening on port 3000

The app works, that's fine. But when I clone an app created in other computer I don't get that message, so I'm supposing I have something outdated in my computer.

I went to the site mentioned in the message and confirmed my speculations. That is a deprecation warning. However, I've updated node and npm and globally express but I still getting the note.

My problem is therefore: I don't know what do I need to update in order to get rid of the deprecation notes because they're freaking me out.

Chenmunka
  • 685
  • 4
  • 21
  • 25
Amet Alvirde
  • 1,453
  • 3
  • 13
  • 22
  • Have you tried using other libraries directly? Such as multiparty (which express uses behind the scenes? ) - there is a good list at http://andrewkelley.me/post/do-not-use-bodyparser-with-express-js.html at the bottom of the post. – guy mograbi Nov 26 '13 at 07:31

3 Answers3

170

This is a warning that will go away once Express updates to use Connect 3.0 - as a temporary fix, follow the instructions at the top of https://github.com/senchalabs/connect/wiki/Connect-3.0. Specifically, find this line in your app:

app.use(express.bodyParser());

And replace it with the following (this is what bodyParser will be in 3.0):

app.use(express.json());
app.use(express.urlencoded());
Jacob Gillespie
  • 3,981
  • 3
  • 23
  • 33
60

i'm responsible for this deprecation notice. did you read the wiki? https://github.com/senchalabs/connect/wiki/Connect-3.0

step 1: use each parser directly instead of app.use(express.bodyParser());

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

step 2: use a different multipart parser, for e.g: connect-multiparty can be used

app.use(require('connect-multiparty')())

work on connect 3 and express 4 hasn't begun yet because node 0.12 is taking a while to be released. there's nothing to update, yet.

NT_
  • 2,216
  • 1
  • 18
  • 23
Jonathan Ong
  • 19,927
  • 17
  • 79
  • 118
  • 1
    It's not a deprecation notice -- it's a breaking change. app.use(express.bodyParser) doesn't work anymore with the latest version but the major version numbers haven't changed for the libs, which breaks the concept of semver. – tkone Dec 23 '13 at 16:22
  • running the latest version from `npm install express`, and doing a very simple: `var express = require('express'), app = express(); app.use(express.bodyParser); app.get('/', function(req,res){ res.send(200, 'ok');}); app.listen(3000);`. Making a request to `http://localhost:3000/` hangs curl & browser & prints warning. Removing `app.use(express.bodyParser)` or switching to `app.use(express.json())` causes app to return "ok" with HTTP Status 200. – tkone Dec 23 '13 at 20:50
  • It's connect-multiparty, instead of connect-multipart – Vince Yuan Mar 11 '14 at 16:39
  • 1
    I wish there was an option to suppress this warning; while deprecation notices are important it's very rare in the enterprise environment to NOT have an option to suppress them. My current situation has me unable to make the necessary changes to avoid the message for at least 6 months but a configuration option I could but now we have these sprinkled throughout our logs in a different format than anything else making our older log parsers not very happy. Just food for thought; deprecation notices are important but devs need a way to get them out of the way if necessary. – Kris Mar 22 '14 at 07:26
  • 1
    @Kris if you can't use the json and urlencoded middleware directly (presumably since you're using the multipart support to handle file uploads) you can momentarily override `console.log` while the bodyParser is instantiated, then bring it back. I used this approach for a period of time in Sails to normalize our log output – mikermcneil May 09 '14 at 01:34
  • @JonathanOng if i remove body parser file upload fails any workaround for that ? – Richie Fredicson Aug 07 '15 at 16:06
1

since express is just a wrapper to connect, i suggest using connect directly.

so instead of: app.use(express.bodyParser());

use:

connect = require('connect');
app.use(connect.json());
app.use(connect.urlencoded());
Sagiv Ofek
  • 25,190
  • 8
  • 60
  • 55