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.
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