FAQ: Middleware - Open-Source Middleware: Logging

This community-built FAQ covers the “Open-Source Middleware: Logging” exercise from the lesson “Middleware”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn Express

FAQs on the exercise Open-Source Middleware: Logging

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I am not sure about the ‘tiny’ format in morgan…
in the morgan document,

tiny

The minimal output.

:method :url :status :res[content-length] - :response-time ms

And after passing the exercise, I wonder if the ‘tiny’ format will only send response like ‘Response Sent’ which is only replaced throughout the exercise.

See if more people can discuss. Cheers!

I agree the tiny format might not be useful in many cases, but there are quite a few others with much more information in the log about the request object. I am sure you’ve seen them above tiny. I think perhaps ‘tiny’ is purely used in this example to not overwhelm the express course learner with extra object info like…

:remote-addr - :remote-user [:date[clf]] and HTTP/:http-version" “:referrer” “:user-agent”

Can you think of any example of when you would use ‘tiny’? I’m not sure.

1 Like

Thanks for discussing!

Just look back two months later, I think what the description says what its use is:

The minimal output.

When managing logs, maybe we don’t need too much information. That why we may use tiny.

1 Like

So I’m a little confused. Does Morgan(‘tiny’) just log the appropriate req/res status or does it log each token included in ‘tiny’ every time a request is made?

morgan(':method :url :status :res[content-length] - :response-time ms');

I ran the code a couple of times. The first was a GET request for ‘cherry’ which is not an appropriate path. The second was a GET request for ‘/beans/cherry’ which elicits the appropriate response. This is what I got in the console.

$ node app.js
Server is listening on port 4001
GET /cherry 404 145 - 1.487 ms
GET /beans/cherry 200 12 - 2.107 ms

It appears each request is logged in the same format.
I hope that answers your question. :slightly_smiling_face:

1 Like

Sweet thank you! Looks like it logs the last 3 tokens.

1 Like

Hey guys.

I passed te task, but somehow morgan does not log anything when I send requests… And this is not the first time, that somehow happened several times through the path… Maybe a bug?

Jep, worked for me as well.

Input in PATH: /beans
Output in console: GET /beans 200 116 - 1.872 ms
Output in browser (Response Body - 200 chars in total):

{
    "mystery": {
        "number": 4
    },
    "lemon": {
        "number": 5
    },
    "rootBeer": {
        "number": 25
    },
    "cherry": {
        "number": 3
    },
    "licorice": {
        "number": 1
    }
}

Input in PATH: /beans/cherry
Output in console: GET /beans/cherry 200 12 - 0.796 ms
Output in browser (Response Body - 12 chars in total):

{
    "number": 3
}