Express.js
Beginner
1 min read
What Is Express.js
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
Related Resources
Express.js Reference
Complete tag & property list
Express.js How-To Guides
Step-by-step practical guides
Express.js Exercises
Practice what you've learned
More in Express.js