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

  1. Install Node.js
    Ensure you have Node.js installed on your machine. If not, download it from nodejs.org.
    ✅ Use the command node -v to verify the installation.

  2. Initialize a Project
    Run npm init -y in your terminal to create a package.json file.
    📁 This file manages your project's dependencies and configurations.

  3. Install Express
    Execute npm install express to add the Express framework to your project.
    📦 Express simplifies building web applications and APIs.

  4. Create Server Code
    Add the following code to a file named server.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

HTTP_Server
NodeJS_Logo

Let us know if you need further assistance! 😊