Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

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

You need a previous version:

npm install express@3.0.0

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top