0

I have just installed node and express. When I run the comman node app.js it gives me following error.

   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
   /var/www/nodeexpress/nodetest1/app.js:38
   console.log("Express server listening on port %d in %s mode", app.address().
                                                                ^
  TypeError: undefined is not a function
  at Server.<anonymous> (/var/www/nodeexpress/nodetest1/app.js:38:69)
  at Server.g (events.js:196:16)
  at Server.EventEmitter.emit (events.js:101:17)
  at net.js:1159:10
  at process._tickCallback (node.js:339:11)
  at Function.Module.runMain (module.js:492:11)
  at startup (node.js:124:16)
  at node.js:803:3

And My app.js looks like

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

//var app = module.exports = express.createServer();
var app = express();

// Configuration

app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({ secret: 'your secret here' }));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
app.use(express.errorHandler());
});

// Routes

app.get('/', routes.index);

app.listen(8080, function(){
console.log("Express server listening on port %d in %s mode", app.address().port,    app.settings.env);
});

It seems that express not getting initalized. My node version is v0.11.13-pre and I hav0.11.13-pree installed express version using package.json as 3.4.4

Awais Qarni
  • 17,492
  • 24
  • 75
  • 137

2 Answers2

3

use this.address().port than app.address().port

address() is a function property of the http object to which the listen function is applied

From connect proto.js:

app.listen = function(){
  var server = http.createServer(this);
  return server.listen.apply(server, arguments);
};

as for the connect.multipart() warning, check this answer: How to get rid of Connect 3.0 deprecation alert?

Community
  • 1
  • 1
balafi
  • 2,143
  • 3
  • 17
  • 20
1

Here is the solution

You need to remove this line because the bodyParser method is not in this version.

app.use(express.bodyParser());

replace with

app.use(express.json());

app.use(express.urlencoded());

Let me know if still facing any issue.

Moiz Raja
  • 5,612
  • 6
  • 40
  • 52
Saran Pal
  • 533
  • 5
  • 9