npm express "hello world" middleware error

17,414

Solution 1

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

Solution 2

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

Solution 3

You need a previous version:

npm install [email protected]
Share:
17,414

Related videos on Youtube

user3543240
Author by

user3543240

Updated on September 14, 2022

Comments

  • user3543240
    user3543240 over 1 year

    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.

  • Tony
    Tony about 8 years
    Should be app.use there instead of app.user.