TypeError: object function (req, res, next) {app.handle (req, res, next); } does not have a 'configure' method

Can someone please indicate why I am getting this error when I try 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 express version 4.x.

+4
source share
2 answers

Express 4.x does not have a configuration method.

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

In addition, it does not express.loggerand is express.bodyParseroutdated a long time ago.

+8
source

new-features-node-express-4 , app.configure - 3.x 4.0.

. "set" "use".

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');
})

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');
}
+10

Source: https://habr.com/ru/post/1530717/


All Articles