SyntaxStudy
Sign Up
Express.js Beginner 1 min read

What Is Express.js

Express.js is a minimal, unopinionated web framework for Node.js that provides a thin layer of fundamental web-application features without obscuring the Node.js features you already know. It handles HTTP routing, middleware integration, and response utilities while leaving architectural decisions to the developer. Installing Express is done via npm: `npm install express`. A minimal server requires only a few lines — create an app instance with `express()`, define a route, and call `app.listen()`. Express sits on top of Node's built-in `http` module, so everything you know about streams and events still applies. Express is the foundation of many larger frameworks such as NestJS and LoopBack. Understanding its core concepts — the application object, request/response cycle, and middleware stack — gives you transferable knowledge across the Node.js ecosystem.
Example
// app.js  –  minimal Express server
const express = require('express');
const app     = express();
const PORT    = process.env.PORT || 3000;

// Parse JSON bodies automatically
app.use(express.json());

// Parse URL-encoded form data
app.use(express.urlencoded({ extended: true }));

// Simple root route
app.get('/', (req, res) => {
    res.json({
        message: 'Hello from Express!',
        timestamp: new Date().toISOString(),
    });
});

// 404 fallback
app.use((req, res) => {
    res.status(404).json({ error: 'Not found' });
});

// Start listening
app.listen(PORT, () => {
    console.log(`Server running on http://localhost:${PORT}`);
});

module.exports = app; // export for testing