0
0
Expressframework~30 mins

Creating a basic Express server - Try It Yourself

Choose your learning style9 modes available
Creating a basic Express server
📖 Scenario: You want to create a simple web server that can respond to visitors with a friendly message. This server will listen for requests and send back a greeting.
🎯 Goal: Build a basic Express server that listens on port 3000 and responds with "Hello, Express!" when someone visits the home page.
📋 What You'll Learn
Create an Express app instance
Set a port number variable
Add a route for the home page that sends a greeting
Start the server listening on the port
💡 Why This Matters
🌍 Real World
Basic Express servers are the foundation for many web applications and APIs.
💼 Career
Understanding how to set up and run an Express server is essential for backend web development roles.
Progress0 / 4 steps
1
Set up Express app
Write const express = require('express') to import Express, then create an app instance with const app = express().
Express
Need a hint?

Use require('express') to import Express and then 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 home page route
Use app.get('/', (req, res) => { ... }) to add a route for the home page that sends the text 'Hello, Express!' with res.send().
Express
Need a hint?

The app.get method defines a route. Use res.send to send the response.

4
Start the server
Call app.listen(port, () => { ... }) to start the server listening on the port. Inside the callback, use console.log to show `Server running on port ${port}`.
Express
Need a hint?

Use app.listen with the port and a callback that logs the server start message.