10

node --version v0.10.26

npm --version 1.4.3

I followed this: http://expressjs.com/guide.html

which has this code

    var express = require('express'),
    app = express();
app.use(express.logger());

app.get('/', function(req, res){
    res.send('Hello World');
});

var server = app.listen(3000, function() {
    console.log('Listening on port %d', server.address().port);
});

I try 'node app.js' in the terminal and I got this error:

Error: Most middleware (like logger) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.

    at Function.Object.defineProperty.get 

(/home/mike/node/helloworld/node_modules/express/lib/express.js:89:13)

    at Object.<anonymous> (/home/mike/node/helloworld/app.js:4:17)

    at Module._compile (module.js:456:26)

    at Object.Module._extensions..js (module.js:474:10)

    at Module.load (module.js:356:32)

    at Function.Module._load (module.js:312:12)

    at Function.Module.runMain (module.js:497:10)

    at startup (node.js:119:16)

    at node.js:902:3

I'm new with express, any help will be welcomed. Thanks.

user3543240
  • 133
  • 1
  • 2
  • 6
  • The error pretty much sums it up, `express.logger()` is no longer included, you have to install it separately. – adeneo Apr 16 '14 at 23:58

4 Answers4

37

The first line tells it all:

Error: Most middleware (like logger) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.

Looking at https://github.com/senchalabs/connect#middleware we can see that express.logger has been replaced with morgan.

var logger = require('morgan');
app.use(logger); //replaces your app.use(express.logger());

Remember to npm install morgan and/or add it to your package.json

6

I faced the same problem. I ran the below from the directory where my node js file was

npm install --save morgan

Using above command adds the dependency to your package.json.

Once package added, logger can now be used as

logger = require('morgan');
app.use(logger('dev'));
Sumit Sinha
  • 61
  • 1
  • 1
1

Most middleware (like logger) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware

express.logger('dev') is removed from express module.

use logger like morgan.

var morgan = require("morgan");
app.use(morgan('combined'));

for more details on morgan checkout the below link morgan

kmonsoor
  • 7,600
  • 7
  • 41
  • 55
Sumeet_Pol
  • 929
  • 8
  • 13
1

You need a previous version:

npm install express@3.0.0
Tunaki
  • 132,869
  • 46
  • 340
  • 423
guest
  • 21
  • 1