How to get rid of Connect 3.0 deprecation alert?
Asked Answered
A

3

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.

Almeria answered 25/10, 2013 at 4:33 Comment(1)
Have you tried using other libraries directly? Such as multiparty (which express uses behind the scenes? ) - there is a good list at andrewkelley.me/post/do-not-use-bodyparser-with-express-js.html at the bottom of the post.Lewiss
A
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());
Akkerman answered 26/10, 2013 at 21:17 Comment(4)
more information on the connect 3.0 issue here: groups.google.com/d/msg/express-js/iP2VyhkypHo/5AXQiYN3RPcJUhlan
I also needed to add app.use(express.multipart()) because my multipart forms stopped working (of course), which also brought back the deprecation warning (of course).Bacardi
use one of the multipart parsers listed in the wiki. don't use connect/express'Finback
THANK! YOU! I was about to go crazyPepperandsalt
F
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.

Finback answered 16/12, 2013 at 11:34 Comment(6)
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.Ungotten
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.Ungotten
It's connect-multiparty, instead of connect-multipartFillet
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.Pullet
@Pullet 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 outputKelleykelli
@JonathanOng if i remove body parser file upload fails any workaround for that ?Rivero
C
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());
Creeper answered 6/3, 2014 at 23:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.