What is Express and why use it?
Express is a framework that wraps Node’s built-in http module and removes the boilerplate. Instead of manually checking req.url and req.method for every route, Express gives you clean, readable syntax for building servers.
How do you set up a basic Express server?
const express = require(‘express’)
const app = express()
app.listen(3000, () => console.log(‘Running on port 3000’))
How do you create routes in Express?
Use app.get(), app.post(), etc. Each takes a path and a callback with req and res:
app.get(‘/users’, (req, res) => {
res.json({ users: [] })
})
What are route parameters?
Dynamic values in a URL path, prefixed with :. Access them via req.params:
app.get(‘/users/:id’, (req, res) => {
console.log(req.params.id) // e.g. “42”
})
What is middleware?
A function that runs between the request coming in and the response going out. It has access to req, res, and next(). Call next() to pass control to the next middleware.
app.use((req, res, next) => {
console.log(${req.method} ${req.url})
next()
})
How do you handle POST requests and read the body in Express?
Add the built-in JSON middleware first, then access req.body:
app.use(express.json()) // must add this!
app.post(‘/users’, (req, res) => {
console.log(req.body) // { name: ‘John’ }
res.json({ success: true })
})
What is MVC?
Model-View-Controller — a way to organise your code into three clear roles:
Model — handles data logic
View — what the user sees
Controller — connects the two, handles requests
What are Express Routers?
A way to split your routes into separate files so app.js doesn’t get massive:
// routes/users.js
const router = express.Router()
router.get(‘/’, (req, res) => res.json([]))
module.exports = router
// app.js
const usersRouter = require(‘./routes/users’)
app.use(‘/users’, usersRouter)
What is a RESTful API?
An API that follows a standard pattern using HTTP methods to perform actions on resources:
GET /launches — read all
POST /launches — create one
PUT /launches/:id — update one
DELETE /launches/:id — delete one
What is CRUD?
The four basic operations every data-driven app needs:
Create → POST
Read → GET
Update → PUT / PATCH
Delete → DELETE