# Exporting functions from modules

**URL:** <https://forum.codewithmosh.com/t/exporting-functions-from-modules/4137>\
**Category:** Node\
**Created:** [April 14, 2021, 5:59pm UTC](https://forum.codewithmosh.com/t/exporting-functions-from-modules/4137 "2021-04-14T17:59:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkoziel](https://avatars.discourse-cdn.com/v4/letter/r/f6c823/32.png) [@rkoziel](https://forum.codewithmosh.com/u/rkoziel)\
**Post date:** [April 14, 2021, 5:59pm UTC](https://forum.codewithmosh.com/t/exporting-functions-from-modules/4137/1 "2021-04-14T17:59:16Z")

</div>

In the middleware unit of the Complete Node.js course, we create a Logger.js module with a log function, and export that with module.exports = log. Then in index.js, this is pulled in with the typical require statement and used with app.use(logger).

Then we pull in some third party middleware, namely helmet and morgan. These are likewise pulled in with require statements, and used as follows:  
app.use(helmet());  
app.use(morgan(‘tiny’));

Hopefully this is not a silly question, but I am trying to figure out why for the logger it is app.use(logger) instead of app.use(logger()) like for helmet and morgan? I have tried playing around with the module.exports in logger.js. I feel like I am overlooking the obvious. Any explanations on this are appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![sufian.babri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sufian.babri/32/1028_2.png) [@sufian.babri](https://forum.codewithmosh.com/u/sufian.babri)\
**Post date:** [April 15, 2021, 2:20am UTC](https://forum.codewithmosh.com/t/exporting-functions-from-modules/4137/2 "2021-04-15T02:20:14Z")

</div>

Interesting question.

Basically the [app.use](http://expressjs.com/en/api.html#app.use) needs a callback function with three parameters (precisely `function (req, res, next)`).

So when you write app.use(logger) it means you are writing:

```auto
app.use(function(req, res, next);

```

And when you write `appuse(helmet())` and `app.use(morgan('tiny'))` , you are actually invoking the functions of helmet and morgan which returns a `function (req, res, next)`.

I hope this clears things up.

---

<div class="post-metadata">

**Author:** ![rkoziel](https://avatars.discourse-cdn.com/v4/letter/r/f6c823/32.png) [@rkoziel](https://forum.codewithmosh.com/u/rkoziel)\
**Post date:** [April 15, 2021, 2:28pm UTC](https://forum.codewithmosh.com/t/exporting-functions-from-modules/4137/3 "2021-04-15T14:28:58Z")

</div>

Thanks for the response. I understand that this is essentially a callback being passed to app.use. My question was more around syntax - while for logger it is app.use(logger) instead of app.use(logger()) like it is for app.use(helmet()) and app.use(morgan(‘tiny’)).
