🌍 NodeJS · subject
NodeJS ExpressJS Framework Syllabus
The ExpressJS Framework syllabus for NodeJS in full: 4 chapters and 10 topics, every one listed below, plus 51 ExpressJS Framework flashcards with answers.
ExpressJS Framework syllabus: all 4 chapters
Expand any chapter to see its topics and sub-topics.
-
Introduction to ExpressJS
2 topics- What is ExpressJS?
- Setting Up ExpressJS
-
Middleware
3 topics- Built-in Middleware
- Third-party Middleware
- Custom Middleware
-
Routing in ExpressJS
3 topics- Basic Routing
- Route Parameters
- Router Module
-
Error Handling
2 topics- Error Handling Middleware
- Centralized Error Handling
NodeJS ExpressJS Framework flashcards — 51 questions with answers
What is ExpressJS?
ExpressJS is a minimal, unopinionated, and flexible web application framework for Node.js that provides a thin layer of features (routing, middleware, HTTP utilities) for building web servers and RESTful APIs.
On which runtime and language does ExpressJS run?
It runs on the Node.js runtime and is written in JavaScript, building on top of Node's built-in HTTP module.
Name three core things ExpressJS simplifies compared to using Node's raw 'http' module.
Routing (mapping URLs/HTTP methods to handlers), middleware processing of requests/responses, and sending responses (e.g. res.json, res.send, res.status).
What does it mean that Express is 'unopinionated'?
It does not enforce a specific project structure, ORM, or way of doing things; developers are free to organize files and choose their own libraries and patterns.
Which two objects are central to nearly every Express handler, and what do they represent?
The request object (req), representing the incoming HTTP request, and the response object (res), used to build and send the HTTP response back to the client.
Which npm command installs ExpressJS into a project as a dependency?
npm install express (optionally 'npm install express --save' on older npm versions, though --save is the default now).
What is the minimal code to create an Express application instance?
const express = require('express'); const app = express(); — 'express()' returns the application object.
How do you start an Express server listening on port 3000?
app.listen(3000, () => console.log('Server running')); — app.listen binds and listens for connections on the given port.
What file typically records Express and its version, and how is a fresh one created?
package.json records dependencies; it is created with 'npm init' (or 'npm init -y' for defaults) before installing Express.
What is the conventional entry-point filename for an Express app, and what does 'require' do?
Conventionally app.js, index.js, or server.js; require() is the CommonJS function used to import the express module and other dependencies.
Define 'middleware' in Express.
Middleware is a function with access to the request object (req), the response object (res), and the next function in the request-response cycle; it can run code, modify req/res, end the cycle, or call next() to pass control.
What is the standard signature of an Express middleware function?
function(req, res, next) { ... } — three parameters: request, response, and the next() callback that passes control to the following middleware.
What happens if a middleware function neither ends the response nor calls next()?
The request hangs (is left pending) because control is never passed on and no response is sent to the client.
What is built-in middleware in Express, and name the three provided by Express 4.16+?
Middleware bundled with Express itself (no extra install). The three are express.json(), express.urlencoded(), and express.static().
What does express.json() do?
It parses incoming requests with JSON payloads (Content-Type application/json) and populates req.body with the resulting JavaScript object.
What does express.urlencoded() parse, and what does the { extended: true } option control?
It parses URL-encoded form bodies (application/x-www-form-urlencoded) into req.body; extended: true uses the qs library allowing rich/nested objects, while extended: false uses the querystring library (flat data only).
What is express.static() used for?
It serves static files (HTML, CSS, images, JS) from a specified directory, e.g. app.use(express.static('public')).
What is third-party middleware, and how is it added to an app?
Middleware written by external packages installed via npm; it is added with app.use() (or on specific routes) after being required, e.g. app.use(morgan('dev')).
Name a common third-party middleware for HTTP request logging.
morgan — logs incoming HTTP requests with details like method, URL, status, and response time.
Which third-party middleware is commonly used to parse cookies, and what does it populate?
cookie-parser; it parses the Cookie header and populates req.cookies with an object of cookie name/value pairs.
Show the other 31 ExpressJS Framework flashcards
Which third-party middleware enables Cross-Origin Resource Sharing in Express?
cors — it sets the appropriate Access-Control-Allow-* headers to permit requests from other origins.
Which popular third-party middleware sets security-related HTTP headers?
helmet — it sets headers like X-Content-Type-Options, Strict-Transport-Security, and others to harden the app against common attacks.
What is custom middleware?
A middleware function you write yourself to implement app-specific logic (logging, authentication checks, request timing, etc.), registered with app.use() or on specific routes.
Write a simple custom logging middleware that logs the method and URL then continues.
app.use((req, res, next) => { console.log(`${req.method} ${req.url}`); next(); }); — it logs and calls next() to continue the cycle.
What is the effect of the order in which middleware is registered with app.use()?
Middleware executes in the order it is registered; each request passes through them top-to-bottom, so ordering (e.g. body parsers before routes) matters.
How do you scope custom middleware to only a specific path?
Pass the path as the first argument, e.g. app.use('/admin', authMiddleware); — the middleware runs only for requests whose path starts with '/admin'.
What is application-level vs router-level middleware?
Application-level middleware is bound to the app instance via app.use()/app.METHOD(); router-level middleware is bound to an express.Router() instance via router.use()/router.METHOD() and applies only to routes on that router.
Define 'routing' in ExpressJS.
Routing is the mechanism of determining how an application responds to a client request to a particular endpoint, defined by a URL path and a specific HTTP method (GET, POST, etc.).
What is the general form of a basic Express route definition?
app.METHOD(PATH, HANDLER) — where METHOD is a lowercase HTTP method, PATH is the route path, and HANDLER is the (req, res) callback, e.g. app.get('/', (req, res) => res.send('Hi')).
Which Express methods handle GET, POST, PUT, and DELETE requests?
app.get(), app.post(), app.put(), and app.delete() respectively.
What does app.all() do?
It matches all HTTP methods for a given path, running the handler regardless of whether the request is GET, POST, PUT, DELETE, etc.
How do you send a plain text vs a JSON response in a route handler?
res.send('text') sends text/HTML; res.json({ key: 'value' }) sends a JSON response with Content-Type application/json.
How can you attach multiple handlers to a single route?
Pass several callbacks (or an array), e.g. app.get('/x', mw1, mw2, finalHandler); each calls next() to reach the following one.
What are route parameters (named URL segments) in Express?
Named segments in the path prefixed with a colon that capture dynamic values from the URL, e.g. '/users/:id' captures the id; captured values live in req.params.
Given the route '/users/:id', how do you access the id value from a request to /users/42?
Via req.params.id, which would be the string '42'.
Can a route have multiple parameters? Give an example.
Yes, e.g. '/users/:userId/books/:bookId' populates req.params.userId and req.params.bookId.
How do route parameters (req.params) differ from query strings (req.query)?
Route parameters are named parts of the URL path (/users/:id), while query strings are key=value pairs after '?' (/users?id=42) accessed via req.query; params identify a resource, query typically filters/options it.
What is app.param() used for?
It registers a callback that runs whenever a specific route parameter is present, useful for validating or pre-loading data (e.g. fetching a user by :id) before the route handlers execute.
What is the Express Router module?
express.Router() creates a modular, mountable mini-application (a 'mini-router') that can have its own routes and middleware, allowing route definitions to be split across files and mounted onto the main app.
How do you create and export a router in a separate file?
const router = express.Router(); router.get('/', handler); module.exports = router; — then mount it in the main app.
How do you mount a router at a base path in the main app?
app.use('/users', usersRouter); — all routes defined in usersRouter are prefixed with '/users'.
Why is the Router module beneficial for larger applications?
It promotes modularity and separation of concerns—grouping related routes and middleware together, keeping files small, and making the codebase easier to maintain and scale.
Can a Router have its own middleware? How?
Yes; via router.use(middleware), which applies the middleware only to routes handled by that router.
What distinguishes error-handling middleware from regular middleware in Express?
Error-handling middleware has four arguments: (err, req, res, next). Express recognizes it by the arity of four parameters and only invokes it when an error is passed.
How do you trigger error-handling middleware from a regular middleware or route?
By calling next(err) with an argument (an Error object); passing any argument to next() (other than the string 'route') signals Express to skip remaining normal middleware and jump to error handlers.
Write the signature of a basic Express error-handling middleware that returns a 500.
app.use((err, req, res, next) => { console.error(err.stack); res.status(500).send('Something broke!'); });
Where should error-handling middleware be placed in the middleware stack, and why?
Last, after all other app.use() and routes, so that errors passed via next(err) from any earlier middleware/route propagate down to it.
In an async route handler, how do you forward a thrown error to Express error handling (pre-Express 5)?
Catch it and call next(err), e.g. wrap in try/catch and 'catch (e) { next(e); }', or use a wrapper/async-handler, because Express 4 does not automatically catch rejected promises.
What is centralized error handling in Express?
A pattern where all errors are routed to a single, dedicated error-handling middleware (defined once, mounted last) that formats and sends consistent error responses, instead of duplicating error logic in every route.
How is a custom Error class typically used in centralized error handling?
You define a class (e.g. AppError) extending Error with properties like statusCode and message; routes throw/next() such errors, and the central handler reads err.statusCode and err.message to build a uniform response like res.status(err.statusCode).json({ error: err.message }).
How do you handle unmatched routes (404) before the centralized error handler?
Add a catch-all middleware after all routes, e.g. app.use((req, res, next) => next(new AppError('Not Found', 404))); which forwards a 404 error to the central error handler.
NodeJS ExpressJS Framework FAQ
What is in the NodeJS ExpressJS Framework syllabus?
NodeJS ExpressJS Framework is split into 4 chapters: Introduction to ExpressJS, Middleware, Routing in ExpressJS and Error Handling. Together they contain 10 topics.
How many chapters are in NodeJS ExpressJS Framework?
4 chapters, containing 10 topics. The largest chapter is Middleware, with 3 topics.
Are there flashcards for NodeJS ExpressJS Framework?
Yes — a 51-card ExpressJS Framework deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.