DEV Community

Cover image for πŸš€ Introduction to Express.js – the framework that changed Node forever
Ramanand Thakur
Ramanand Thakur

Posted on

πŸš€ Introduction to Express.js – the framework that changed Node forever

Express.js made backend development in JavaScript ridiculously simple. Before Express, building APIs in Node felt like assembling IKEA furniture without the manual πŸ˜….


🧠 The JavaScript Revolution

There was a time when JavaScript lived only inside browsers.

Frontend? JavaScript.
Backend? Mostly PHP, Java, Python, Ruby, or .NET.

Then came Node.js in 2009 and everything changed.

Suddenly, developers could write JavaScript on both:

  • πŸ–₯️ Client side (browser)
  • 🌐 Server side (backend)

Yes, this was a massive shift.

Teams no longer needed separate frontend and backend language expertise. One language could handle:

  • UI rendering
  • API development
  • Real-time chat apps
  • Streaming
  • File handling
  • Even CLI tools

And this is where Express.js entered like a Bollywood hero in slow motion 🎬.


⚑ Introducing Express

Express.js is a lightweight web framework built on top of Node.js.

Think of Node.js as the raw engine of a car πŸš—.

Express gives you:

  • Steering wheel
  • Dashboard
  • Brakes
  • Air conditioning
  • And sane defaults πŸ˜„

Without Express, building APIs in pure Node means manually handling:

  • Routing
  • Headers
  • Request parsing
  • Response formatting
  • Middleware chaining

Express simplifies all of that.


πŸ“¦ Installing Express

Prerequisites

  • Node.js v18+
  • Basic JavaScript knowledge (Watch any quick 30 minutes tutorial on YT)
  • npm installed
  • β˜• 2 cups of coffee

πŸ› οΈ Your First Express Server

mkdir express-demo
cd express-demo

npm init -y
npm install express
Enter fullscreen mode Exit fullscreen mode

Now create server.js.

// Node v20 + Express 4

const express = require('express');

const app = express();

// Route handler
app.get('/', (req, res) => {
  res.send('Hello from Express πŸš€');
});

// Start server
app.listen(3000, () => {
  console.log('Server running on http://localhost:3000');
});
Enter fullscreen mode Exit fullscreen mode

Run it:

node server.js
Enter fullscreen mode Exit fullscreen mode

Open browser:

http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

And boom πŸ’₯ β€” backend server ready in less than 10 lines.


🌍 Server-side vs Client-side Applications

This is where many beginners get confused.

Let’s simplify it.

πŸ–₯️ Client-side Applications

Client-side apps run in the browser.

Examples:

  • React
  • Angular
  • Vue

Responsibilities:

  • Rendering UI
  • Handling clicks
  • Animations
  • Calling APIs

🌐 Server-side Applications

Server-side apps run on servers.

Responsibilities:

  • Database operations
  • Authentication
  • Business logic
  • API responses
  • Security

πŸ“Š How They Talk To Each Other

client-server-communication

This separation is the backbone of modern web apps.


πŸ“œ A Brief History of Express

Express was created by TJ Holowaychuk around 2010.

Back then, Node.js was still young.

Developers loved Node’s speed, but building servers directly with Node’s http module was painful.

Here’s how raw Node looked:

// Pure Node.js HTTP server 😡

const http = require('http');

const server = http.createServer((req, res) => {
  if (req.url === '/') {
    res.writeHead(200, {
      'Content-Type': 'text/plain'
    });

    res.end('Hello World');
  }
});

server.listen(3000);
Enter fullscreen mode Exit fullscreen mode

Not terrible… until your app grows to 50 routes and middleware chains.

Express solved that elegantly.


βš”οΈ Node.js vs Traditional Web Servers

Before Node.js, most web servers worked like this:

🧡 Traditional Web Servers (Apache, PHP, Java)

Request Flow

traditional web server flow

Every request often created:

  • New thread
  • More memory usage
  • Context switching overhead

Works fine… until traffic explodes 🚦.


⚑ Node.js Architecture

Request Flow

nodejs server

Node uses:

  • Single-threaded event loop
  • Non-blocking I/O
  • Async processing

This is why Node became insanely popular for:

  • Real-time apps
  • APIs
  • Streaming
  • Chat systems
  • Notification services

β˜• Caffeine Scale

Topic Complexity
Basic Express routes β˜•
Middleware β˜•β˜•
Event loop internals β˜•β˜•β˜•β˜•

🌱 The Node Ecosystem

One of Node’s biggest strengths is the ecosystem.

The package manager npm exploded in popularity because developers could share reusable libraries instantly.

Today there are millions of packages.

Some famous ones:

Package Purpose
express Web framework
mongoose MongoDB ORM
socket.io Real-time communication
dotenv Environment variables
jsonwebtoken JWT authentication
nodemon Auto restart during development

πŸ“„ Licensing

Express is open-source software released under the MIT License.

That means:

βœ… Free to use
βœ… Free to modify
βœ… Free for commercial projects

This openness helped Express spread rapidly across startups and enterprises alike.

Even huge companies adopted it because there were no painful licensing restrictions.


❌ Common Beginner Mistakes

(Try these fixes you face issue running your first express backend)

1️⃣ Forgetting Middleware

// ❌ req.body will be undefined

app.post('/login', (req, res) => {
  console.log(req.body);
});
Enter fullscreen mode Exit fullscreen mode

βœ… Correct Version

// Express 4.18+

app.use(express.json());

app.post('/login', (req, res) => {
  console.log(req.body);
  res.send('Body parsed correctly');
});
Enter fullscreen mode Exit fullscreen mode

2️⃣ Blocking the Event Loop

// ❌ Very dangerous for performance

while(true) {
  // Infinite blocking loop πŸ’₯
}
Enter fullscreen mode Exit fullscreen mode

Node works best when operations stay async.


πŸ“Š Express vs Traditional Backend Frameworks

Feature Express.js Traditional Java Frameworks
Language JavaScript Java
Performance Excellent for I/O Excellent for CPU-heavy work
Learning Curve Easy Moderate
Boilerplate Minimal Often verbose
Real-time Support Excellent Good
Startup Speed Fast Slower

🎯 Conclusion

Express.js became popular because it made backend development:

  • Simpler
  • Faster
  • More readable
  • More JavaScript-friendly

Key takeaways:

  • πŸš€ Express simplified Node.js web development
  • 🌐 Node introduced a non-blocking server model
  • πŸ“¦ npm created one of the biggest developer ecosystems ever
  • ⚑ Express is ideal for APIs and real-time applications
  • πŸ”“ Open-source licensing accelerated adoption worldwide

And honestly? Once you build your first Express API, going back to raw HTTP servers feels like manually washing clothes after buying a washing machine πŸ˜„.


πŸ”₯ What’s Next?

In the next part, we’ll dive deeper in:

  • Using the Terminal
  • Using Editor
  • Using NPM (Node Package Manager)
  • Event-Driven Programming
  • Routing
  • Serving static resources

πŸ’¬ Your Turn

What was your first backend framework?

PHP? Django? Spring Boot? Express?

And have you ever crashed a production server accidentally? πŸ˜…


πŸ“’ Call To Action

If this helped you understand Express better:

  • ⭐ Share it with another developer
  • πŸ” Bookmark for revision
  • πŸš€ Try building a tiny REST API today
  • πŸ‘¨β€πŸ’» Follow for more deep-dive backend content

Top comments (0)