0
0
Expressframework~30 mins

Morgan for HTTP request logging in Express - Mini Project: Build & Apply

Choose your learning style9 modes available
Morgan for HTTP request logging
📖 Scenario: You are building a simple Express web server. You want to log every HTTP request your server receives to help monitor traffic and debug issues.
🎯 Goal: Set up the morgan middleware in an Express app to log HTTP requests in the 'tiny' format.
📋 What You'll Learn
Create an Express app instance called app
Import and use the morgan middleware with the 'tiny' format
Add a basic route / that sends 'Hello World!'
Start the server on port 3000
💡 Why This Matters
🌍 Real World
Logging HTTP requests helps developers monitor traffic and troubleshoot issues in web servers.
💼 Career
Understanding middleware like Morgan is essential for backend developers and DevOps engineers to maintain and debug web applications.
Progress0 / 4 steps
1
Create the Express app
Import express and create an Express app instance called app.
Express
Need a hint?

Use const app = express(); to create the app.

2
Import and configure Morgan middleware
Import morgan and use it as middleware in app with the 'tiny' format.
Express
Need a hint?

Use app.use(morgan('tiny')); to add logging.

3
Add a basic route
Add a GET route for '/' that sends the text 'Hello World!' as the response.
Express
Need a hint?

Use app.get('/', (req, res) => { res.send('Hello World!'); });

4
Start the server
Start the Express server on port 3000 and print 'Server running on port 3000' when it starts.
Express
Need a hint?

Use app.listen(3000, () => { console.log('Server running on port 3000'); });