Express gives you access to the full HTTP request via req and the response via res.
Reading from the request
app.get('/search', (req, res) => {
const q = req.query.q // ?q=hello → "hello"
res.json({ query: q })
})
app.get('/users/:id', (req, res) => {
// ...Setting response status and headers
res.status(201).json({ created: true })
res.setHeader('X-Custom', 'value')
res.status(404).json({ error: 'Not found' })GET /greet?name=Alice → responds { "message": "Hello, Alice!" }name is missing → responds { "error": "name is required" } with status 400"Greet API ready" on start then close.Express gives you access to the full HTTP request via req and the response via res.
Reading from the request
app.get('/search', (req, res) => {
const q = req.query.q // ?q=hello → "hello"
res.json({ query: q })
})
app.get('/users/:id', (req, res) => {
// ...Setting response status and headers
res.status(201).json({ created: true })
res.setHeader('X-Custom', 'value')
res.status(404).json({ error: 'Not found' })GET /greet?name=Alice → responds { "message": "Hello, Alice!" }name is missing → responds { "error": "name is required" } with status 400"Greet API ready" on start then close.