-1

I am getting

connect deprecated multipart: use parser (multiparty, busboy, formidable) npm module instead at node_modules\express\node_modules\connect\lib\middleware\bodyParser.js
connect deprecated methodOverride: use method-override npm module instead at app.js:22:17
D:\login\node_modules\express\lib\router\index.js:306
    throw new Error(msg);
    ^

Error: .post() requires callback functions but got a [object Undefined]
    at D:\login\node_modules\express\lib\router\index.js:306:11
    at Array.forEach (native)
    at Router.route (D:\login\node_modules\express\lib\router\index.js:302:13)
    at Router.(anonymous function) [as post] (D:\login\node_modules\express\lib\router\index.js:333:16)
    at Function.app.(anonymous function) [as post] (D:\login\node_modules\express\lib\application.js:467:26)
    at Object. (D:\login\app.js:32:5)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

in my node with express.Express version is 3 and I am unable to start the app.js file.

Here is the app.js file :

/**  * Module dependencies.  */

var express = require('express');
var routes = require('./routes');
var signup = require('./routes/login');
var login = require('./routes/signup');
var http = require('http');
var path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 8000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({secret: 'secretkeyQWERTY'}));
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')){
  var use=app.use(express.errorHandler());
}

app.get('/', routes.index);
app.post('/signup', signup.signup);
app.post('/login', login.login);


http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
mscdex
  • 104,356
  • 15
  • 192
  • 153
  • 1
    Can you add example code of what your app.js has? – technicallyjosh Sep 21 '15 at 03:36
  • 1
    This is a warning that was given when using `express.bodyParser()` because support for `express.multipart()`, which was previously bundled, was removed from Connect and Express. Related: [How to get rid of Connect 3.0 deprecation alert?](http://stackoverflow.com/questions/19581146/how-to-get-rid-of-connect-3-0-deprecation-alert) – Jonathan Lonowski Sep 21 '15 at 03:50
  • 2
    One might ask "why in the world are you using express 3"? – jfriend00 Sep 21 '15 at 04:07

1 Answers1

5

I just tested this with express 3.x.

You can easily solve this by installing the body-parser package. The connect built in body-parser in express is deprecated.

npm install --save body-parser
npm install --save method-override

Assuming that you want to accept JSON as the body...

Change your code:

app.use(express.bodyParser())
app.use(express.methodOverride())

to:

var bodyParser = require('body-parser');
var methodOverride = require('method-override')
app.use(bodyParser.json());
app.use(methodOverride());
num8er
  • 18,604
  • 3
  • 43
  • 57
technicallyjosh
  • 3,511
  • 15
  • 17
  • Did you remove the previous app.use() statement? I cannot reproduce the issue after changing that statement – technicallyjosh Sep 21 '15 at 04:06
  • Yes I did it.But still "connect deprecated methodOverride: use method-override npm module instead at app.js" is there ! – Soham Badheka Sep 21 '15 at 04:29
  • remove the line: app.use(express.methodOverride()); – num8er Sep 21 '15 at 04:30
  • So that's a different issue with method override. Is there a reason why you can't upgrade to v4.x.x? Each middleware got separated into different packages. Basically in a nutshell, you will need to do what I showed you for body parser for each middleware. example: [method-override](https://github.com/expressjs/method-override) – technicallyjosh Sep 21 '15 at 04:31
  • @technicallyjosh, it's kind of a requirement to use version 3 now. Removing override method is okay but the error is ".post() requires callback functions but got a [object Undefined] " – Soham Badheka Sep 21 '15 at 04:36
  • Sorry, would have to see what is defined in your post definitions. You currently have `app.post('/signup', signup.signup);` and `app.post('/login', login.login);` standard wire-up of what signup.signup would be `function (req, res, next) {}` – technicallyjosh Sep 21 '15 at 04:38
  • Should I upload it to my github and give you the link? Because I had one project on express with same configuration, it worked like a charm. So as far as the logic is concerned, there is not a problem. – Soham Badheka Sep 21 '15 at 04:57
  • Now this is the new error ! "D:\login\node_modules\express\lib\router\index.js:306 throw new Error(msg); " – Soham Badheka Sep 21 '15 at 06:08