0
0
Node.jsframework~30 mins

Third-party middleware usage in Node.js - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Third-Party Middleware in Node.js
📖 Scenario: You are building a simple web server using Node.js and Express. You want to add a third-party middleware to log details of every request your server receives. This helps you see what requests come in, like checking a guestbook to know who visited.
🎯 Goal: Build a Node.js Express server that uses the morgan middleware to log HTTP requests to the console.
📋 What You'll Learn
Create an Express app instance
Install and import the morgan middleware
Configure morgan to log requests using the 'tiny' format
Start the server listening on port 3000
💡 Why This Matters
🌍 Real World
Logging HTTP requests helps developers monitor and debug web servers by showing who accessed what and when.
💼 Career
Using third-party middleware like Morgan is a common task in backend development jobs to add features quickly and reliably.
Progress0 / 4 steps
1
Create Express app instance
Write code to import express and create an Express app instance called app.
Node.js
Need a hint?

Use require('express') to import Express and then call express() to create the app.

2
Import Morgan middleware
Add code to import the morgan middleware using require('morgan') and save it in a variable called morgan.
Node.js
Need a hint?

Use const morgan = require('morgan'); to import Morgan.

3
Use Morgan middleware in app
Configure the Express app app to use morgan middleware with the 'tiny' format by calling app.use(morgan('tiny')).
Node.js
Need a hint?

Use app.use() to add Morgan middleware with the 'tiny' logging format.

4
Start server on port 3000
Add code to start the Express app listening on port 3000 using app.listen(3000).
Node.js
Need a hint?

Use app.listen(3000) to start the server on port 3000.