0
0
Expressframework~15 mins

What is Express - Hands-On Activity

Choose your learning style9 modes available
What is Express
📖 Scenario: You want to create a simple web server that can respond to requests from a browser or other clients.
🎯 Goal: Build a basic Express server that listens on a port and responds with a message when accessed.
📋 What You'll Learn
Create a variable called express that requires the Express library
Create an Express app instance called app
Set a port number variable called port with the value 3000
Add a route handler for GET requests to / that sends the text 'Hello from Express!'
Start the server listening on the port variable
💡 Why This Matters
🌍 Real World
Express is used to build websites, APIs, and backend services that respond to user requests over the internet.
💼 Career
Knowing Express is essential for backend web development jobs using Node.js, as it is one of the most popular frameworks.
Progress0 / 4 steps
1
Setup Express and create app
Create a variable called express that requires the Express library 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 the app.

2
Set the port number
Create a variable called port and set it to 3000.
Express
Need a hint?

Use const port = 3000; to set the port number.

3
Add a route handler
Use app.get with path '/' and a callback function with parameters req and res. Inside the callback, use res.send('Hello from Express!') to send the response.
Express
Need a hint?

Use app.get to handle GET requests to the root path and send a simple text response.

4
Start the server
Use app.listen with the port variable and a callback function that does nothing or logs a message.
Express
Need a hint?

Use app.listen(port, () => { }) to start the server listening on the port.