guagay_wk
guagay_wk

Reputation: 28050

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?

Upvotes: 0

Views: 106

Answers (2)

weebsta
weebsta

Reputation: 82

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

Upvotes: 2

Gaurav joshi
Gaurav joshi

Reputation: 1799

This implies that you are:- Create a new morgan logger middleware function using the given format (Combined)

You can also do the same as follows:-

var express = require('express')
var morgan = require('morgan')
var app = express()
app.use(morgan('combined'))

Upvotes: 1

Related Questions