“JavaScript is eating the world of software.” That line has been repeated in developer circles for over a decade, and Node.js is a big reason why. Today, more than 42% of professional developers use Node.js to build scalable applications. That’s a number you can’t ignore.
If you’ve worked with JavaScript in the browser, you already hold the key to server-side programming. The only difference is that with Node.js, your code runs on the server instead of inside Chrome or Firefox. Add Express.js into the mix, and you suddenly have a streamlined way to handle routes, responses, and the overall flow of your web app.
In this lesson, we’ll walk through practical steps: installing Node.js, setting up Express, and creating a working project structure you can build upon. You’ll see how the MVC pattern (Model, View, Controller) fits into the picture, and why it matters when your application grows.
No theory overload, no fluff. Just actionable knowledge you can use right after reading. By the end, you’ll not only understand what Node.js and Express are—you’ll have a working app running on your machine!
Key Terms and Definitions
Before diving into installation and coding, it’s important to clarify the terms you’ll see repeatedly in any Node.js tutorial. These concepts form the foundation of working with Node.js and Express.
- Node.js – A JavaScript runtime built on Google Chrome’s V8 engine. It allows JavaScript to run outside the browser, making it possible to build scalable servers and APIs. Example: Running a chat application backend using Node.js.
-
npm (Node Package Manager) – A package manager that comes with Node.js. It helps developers install, update, and manage libraries.
Example: Installing Express with
npm install express
. -
Express.js – A fast and minimal web application framework for Node.js. It simplifies routing, middleware, and handling server responses.
Example: Creating routes like
/login
or/grades
in a grading portal. -
MVC (Model–View–Controller) – A design pattern that separates concerns in an application.
- Model: Manages data and logic. Example: A Student model that saves and retrieves student records.
- View: Handles presentation. Example: An HTML page that displays student grades.
- Controller: Connects everything by handling requests and responses. Example: A GradesController that fetches grades and passes them to the view.
Node.js Overview
Why do so many developers use Node.js for server-side JavaScript? The answer lies in its speed and flexibility. Here are the main reasons:
- Fast and lightweight, thanks to the V8 engine.
- Uses non-blocking I/O, so it can handle multiple requests simultaneously.
- Event-driven architecture, making it efficient for real-time applications.
- Massive ecosystem of reusable packages through npm.
It’s also crucial to understand the difference between browser JavaScript and Node.js:
- Browser JavaScript: Runs on the client side, can manipulate the DOM (HTML, CSS).
- Node.js: Runs on the server side, can access files, databases, and handle HTTP requests.
Installing Node.js and npm
To start building applications with Node.js and Express, you first need to install Node.js. This installation also includes npm, which you’ll use to manage packages and dependencies.
Step 1: Download Node.js
Visit the official Node.js website: https://nodejs.org and download the LTS (Long-Term Support) version. The LTS release is recommended for most developers since it’s stable and widely supported.
Step 2: Verify Installation
After installation, open your terminal or command prompt and check the installed versions:
node -v
npm -v
If you see version numbers, it means your installation was successful. You now have both Node.js and npm ready to go.
Step 3: Test Node.js with REPL
To confirm that Node.js is running properly, enter the following command in your terminal:
node
console.log("Hello from Node!");
You’ll see the message displayed in the terminal. Unlike the browser console, Node.js does not have access to the DOM (HTML or CSS). Instead, it’s designed for server-side JavaScript tasks like working with files, databases, and APIs.
Setting Up a Basic Express Project
Once Node.js and npm are installed, the next step is to set up an Express.js project. Express makes it easier to handle routing, requests, and responses in your applications. Let’s go step by step.
Step 1: Create a New Project Folder
mkdir myapp
cd myapp
Step 2: Initialize npm
This command will generate a package.json
file, which keeps track of your project’s dependencies:
npm init -y
Step 3: Install Express
Now install Express.js using npm:
npm install express
Step 4: Project Folder Structure
A good project layout helps organize your code as it grows. Here’s a suggested folder structure:
myapp/
│ package.json
│ server.js
├── models/
├── views/
├── controllers/
├── routes/
└── public/
Step 5: Create server.js
This file will act as the entry point of your application. Copy the following code:
const express = require('express');
const app = express();
const PORT = 3000;
app.get('/', (req, res) => {
res.send('Hello World from Node.js and Express!');
});
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});
Step 6: Run the Server
node server.js
Now open your browser and go to http://localhost:3000. You should see the message: Hello World from Node.js and Express!
MVC in a Real-World System Examples
The MVC pattern (Model–View–Controller) is not just theory—it’s a practical way to structure applications. By dividing responsibilities into three parts, you make your code more organized, maintainable, and scalable. Let’s look at two examples where MVC is applied in everyday systems.
Example 1: Online Store
- Model: Product, Cart, User.
- View: Webpages that display the product catalog, shopping cart, and checkout page.
- Controller: Functions that handle adding products to the cart, checking out, and processing orders.
Example 2: Grading Portal
- Model: Student, Subject, Grade.
- View: Webpages that show student profiles and grade reports.
- Controller: Functions that fetch grades from the database and deliver them to the correct view.
In both examples, notice how each component has a clear responsibility. The Model manages the data, the View presents it, and the Controller acts as the bridge between them. This structure helps avoid mixing business logic with presentation, which keeps your applications clean and professional.
Lesson 2 Resources
Expand Your Knowledge
Dive deeper into technology and productivity with these related articles:
- Understanding IT – Build a solid foundation in Information Technology essentials.
- Specialist vs Generalist – 85% of companies now seek hybrid talent. Discover whether to specialize or generalize in your career, with actionable strategies to become a T-shaped professional and future-proof your skills.
- Prompt Engineering: Writing Effective AI Prompts – Master the skill of crafting precise AI prompts for better results.
- Understanding Brain Rot in the Digital Age – Break free from digital overload and regain focus.
- Effective Study Techniques for Better Learning – Discover research-backed strategies to boost learning retention.
No comments yet. Be the first to share your thoughts!