Lesson 17 of 30
Express.js
57% complete
Chapters
Chapter 17
Express.js
Learn how Express.js simplifies Node.js web and API development.
Theory
Express.js is a web application framework for Node.js.
It provides features for:
• Routing
• Middleware
• HTTP request handling
• REST APIs
• Error handling
Express makes it easier to build web servers and APIs compared with using the Node.js HTTP module directly.
Example
Node.js Example
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello Express");
});
app.listen(3000, () => {
console.log("Server running");
});Output
An Express server responds with Hello Express.
Practice
Create an Express server with a home route and an about route.
Interview Questions
1.
What is Express.js?
2.
Why is Express used with Node.js?
3.
What is routing in Express?
Quick Quiz
Which option best matches this chapter?
A.A Node.js web framework
B.A database
C.A CSS preprocessor
D.A Python runtime
Answer: A Node.js web framework