Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Which NPM library is specifically designed to act as an Express middleware that automatically tracks and logs HTTP request details (like status codes, URLs, and response latency)?
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Logging Practice pipeline. Include the setup and basic execution steps.
You are reviewing a Node Logging Practice pipeline and the output is incorrect. Reorder the following pipeline stages in the correct logical order to fix the bug: Input Data, Process, Output.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Logging the raw Morgan stream to stdout in production and never persisting it
// Wrong: logs vanish when the process restarts
app.use(morgan('dev'));
// Correct: pipe into a persistent Winston transport
app.use(morgan('combined', {
stream: { write: (msg) => logger.info(msg.trim()) }
}));The Solution //
app.use(morgan('dev')) only prints colorized text to the console ā once the container restarts or the process exits, those logs are gone forever. In production, pipe Morgan's stream option into Winston (or another persistent transport/log aggregator) so requests are written to files or shipped to a log platform, not just flashed on a terminal nobody is watching.
The Error //
Setting AsyncLocalStorage context after asynchronous work has already started
// Wrong: store is set up after next() already ran downstream code
next();
als.run({ reqId }, () => {});
// Correct: wrap the whole request inside run()
als.run({ reqId }, () => {
next();
});The Solution //
als.run() must wrap the entire lifetime of the request ā if you call it after an await or inside a callback that already escaped the original scope, code deeper in the chain will find an empty store because it isn't running inside that closure anymore. Wrap it at the very top of the request middleware, before calling next().