javascriptnode.jsmorgan

morgan deprecated expressjs


I'm learning nodejs an going through tutorial. I faced a problem that tutorial is for older version.

I have that code:

var express = require('express'),
    stylus = require('stylus'),
    logger = require('morgan'),
    bodyParser = require('body-parser');

var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development';

var app = express();

function compile(str, path){
    return stylus(str).set('filename', path);
}

app.set('views', __dirname + '/server/views');
app.set('view engine', 'jade');
app.use(logger);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(stylus.middleware(
        {
            src: __dirname + '/public',
            compile: compile
        }
    ));
app.use(express.static(__dirname + '/public'));


app.get('*', function(req, res) {
  res.render('index');
});

var port = 3131;
app.listen(port);
console.log('Listening on port ' + port + '...');

and when I'm trying to go in http://localhost:3131/ website stops responding in browser

This site can’t be reached

The connection was reset.

in nodemon it says that: enter image description here

If I remove morgan everything works OK. How can I solve that?


Solution

  • The error logs shows "Morgan deprecated default format: use combined format".

    It's quite simple, replace

    app.use(logger);

    with

    app.use(logger('combined'));