Welcome to Example 6 of our documentation series! This guide will walk you through setting up a basic HTTP server using Node.js and Express. Whether you're a beginner or looking to refine your skills, this content is tailored for you.
🧩 Step-by-Step Setup
Install Node.js
Ensure you have Node.js installed on your machine. If not, download it from nodejs.org.
✅ Use the commandnode -v
to verify the installation.Initialize a Project
Runnpm init -y
in your terminal to create apackage.json
file.
📁 This file manages your project's dependencies and configurations.Install Express
Executenpm install express
to add the Express framework to your project.
📦 Express simplifies building web applications and APIs.Create Server Code
Add the following code to a file namedserver.js
:const express = require('express'); const app = express(); const port = 3000; app.get('/', (req, res) => { res.send('Hello World!'); }); app.listen(port, () => { console.log(`Server running at http://localhost:${port}`); });
🖥️ Save the file and run
node server.js
to start the server.
📘 Additional Resources
For deeper insights into Express and HTTP servers, check out our Advanced Topics guide. It covers routing, middleware, and more!
📷 Visual Aids
Let us know if you need further assistance! 😊