Welcome to the Node.js Express Tutorial! Express is a popular web application framework for Node.js that simplifies building APIs and websites. Let's walk through creating a basic HTTP server using Express.

🧰 Prerequisites

  • Node.js installed on your machine
  • Basic JavaScript knowledge

📌 Step-by-Step Guide

  1. Initialize a Project
    Open your terminal and run:

    npm init -y
    

    This creates a package.json file for your project.

  2. Install Express
    Use npm to install Express:

    npm install express
    
  3. Create the Server
    Create a file app.js and add:

    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}`);  
    });  
    
    Express.js Logo
  4. Run the Server
    Execute:

    node app.js
    

    Visit http://localhost:3000 in your browser to see "Hello World!"!

🌐 Key Features of Express

  • Routing: Define routes for different HTTP methods (GET, POST, etc.).
  • Middleware: Add custom logic for request handling.
  • Templating: Render HTML templates with dynamic data.

For more advanced topics, check out our Node.js with MongoDB tutorial!

📚 Tips for Beginners

Happy coding! 🌱