0
0
Expressframework~30 mins

Express application structure - Mini Project: Build & Apply

Choose your learning style9 modes available
Express Application Structure
📖 Scenario: You are building a simple Express web server to serve a homepage and an about page.This project will guide you to create the basic structure of an Express application step-by-step.
🎯 Goal: Build a basic Express app with a main server file, a router for two routes, and start the server on port 3000.
📋 What You'll Learn
Create an Express app instance
Set up a router with two routes: '/' and '/about'
Use the router in the app
Start the server listening on port 3000
💡 Why This Matters
🌍 Real World
Express is a popular framework to build web servers and APIs in Node.js. This basic structure is the foundation for many web applications.
💼 Career
Understanding Express app structure is essential for backend development roles using Node.js, enabling you to build and maintain web servers.
Progress0 / 4 steps
1
Create the Express app instance
Write code to import express and create an Express app instance called app.
Express
Need a hint?

Use require('express') to import Express and call it as a function to create app.

2
Create a router with two routes
Create a router called router using express.Router(). Add two routes: router.get('/', ...) that sends 'Home Page' and router.get('/about', ...) that sends 'About Page'.
Express
Need a hint?

Use express.Router() to create router. Use router.get to define routes and res.send to send text responses.

3
Use the router in the app
Use app.use('/', router) to connect the router to the app so it handles requests starting with '/'.
Express
Need a hint?

Use app.use with the path '/' and the router to connect routes.

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

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