Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Object function (req, res, next) { app.handle(req, res, next); } has no method 'configure'

Can anyone point out why am I getting this error when I am trying to run the following code ?

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

 var app = express();

 //all environments
 app.configure(function () {
 app.use(express.logger('dev')); 
 app.use(express.bodyParser());
});


app.post('/loginUser',login.loginUser);


app.listen(3000);

console.log("Listening on port 3000...");

I am using node.js with the express 4.x version.

like image 626
msrameshp Avatar asked Dec 02 '22 16:12

msrameshp


2 Answers

Tom in his blog post new-features-node-express-4 provides examples of how to convert from using app.configure in express version 3.x to removing it in express version 4.0.

For convenience I added the code example below. In the examples below you can replace "set" with "use".

Version 3.x

// all environments
app.configure(function(){
  app.set('title', 'Application Title');
})

// development only
app.configure('development', function(){
  app.set('mongodb_uri', 'mongo://localhost/dev');
})

// production only
app.configure('production', function(){
  app.set('mongodb_uri', 'mongo://localhost/prod');
})

Version 4.0

// all environments
app.set('title', 'Application Title');

// development only
if ('development' == app.get('env')) {
  app.set('mongodb_uri', 'mongo://localhost/dev');
}

// production only
if ('production' == app.get('env')) {
  app.set('mongodb_uri', 'mongo://localhost/prod');
}
like image 162
Mike Barlow - BarDev Avatar answered Dec 10 '22 12:12

Mike Barlow - BarDev


Express 4.x does not have configure method.

https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x

Also, it doesn't have express.logger and express.bodyParser had been deprecated ages ago.

like image 22
alex Avatar answered Dec 10 '22 11:12

alex