Search code examples
javascriptnode.jsexpresspassport.jspassport-local

What does this require() statement mean?


I am looking at the code example in https://github.com/mjhea0/passport-local-express4

I encountered this require() statement.

app.use(require('morgan')('combined'));

All the other require statements I have used looks something like var XXX = require('module_name');

What does app.use(require('morgan')('combined')); mean? Load both 'morgan' and 'combined' modules?


Solution

  • Better practice to declare your dependencies all in one place. You can do something like this:

    var morgan = require('morgan');
    
    ...
    
    app.use(morgan('combined')) /* combined is added as a parameter of morgan */
    

    Makes your codebase easier to maintain.

    See docs here: https://github.com/expressjs/morgan