Node.js REST API MCQ questions
Take a short practice test with instant feedback, then revise every question with its answer and the reason behind it.
- Questions
- 94
- From lessons
- 74
- Your last test
- —
Practice test
Generating the spec from the same code that defines routes helps keep the docs accurate.
All questions with answers
Which method should create a new resource in a collection?
Show answer
Answer: B. POST
POST /api/products creates a product; the server assigns the id.
What does REST stand for?
Show answer
Answer: B. Representational State Transfer
REST is an architectural style described by Roy Fielding.
Which status code means “validation failed”?
Show answer
Answer: B. 400
400 Bad Request (or 422) with details about each invalid field.
Which status code fits a successful DELETE with no body?
Show answer
Answer: C. 204
204 No Content.
Which status code means “authenticated but not allowed”?
Show answer
Answer: B. 403
401 means not authenticated; 403 means authenticated but forbidden.
Which library is commonly used to validate request bodies?
Show answer
Answer: A. zod
zod (or joi, express-validator) describes and checks input shapes.
Which Express object groups routes into a module?
Show answer
Answer: B. express.Router()
A router is mounted with app.use("/api/products", router).
Which query safely limits page size from user input?
Show answer
Answer: B. LIMIT ? with Math.min(Number(size) || 20, 100)
Convert, default and cap the value, then bind it as a parameter.
What does the cors package do when origin is set to a specific URL?
Show answer
Answer: B. Sends Access-Control-Allow-Origin for that origin
The browser then lets pages from that origin read the response.
Which header carries a bearer token?
Show answer
Answer: B. Authorization: Bearer <token>
The standard is Authorization: Bearer followed by the token.
What are the three parts of a JWT?
Show answer
Answer: A. Header, payload, signature
Each part is base64url-encoded and separated by dots.
Is a JWT payload encrypted?
Show answer
Answer: B. No, it is only encoded and signed
Anyone can read it; never put secrets in it.
What status should a rate limiter return when the limit is hit?
Show answer
Answer: B. 429
429 Too Many Requests, ideally with a Retry-After header.
What is wrong with this route?
JavaScript Illustrative app.delete('/api/orders/:id', requireAuth, async (req, res) => { await pool.query('DELETE FROM orders WHERE id = ?', [req.params.id]); res.sendStatus(204); });Show answer
Answer: B. Any logged-in user can delete any order — ownership is not checked
Check that the order belongs to req.user (or that the user is an admin) — broken object-level authorization.
Which response suits GET /api/products/999 when it does not exist?
Show answer
Answer: C. 404 with an error body
404 Not Found tells the client the resource does not exist.
Where should a refresh token usually be stored in a browser app?
Show answer
Answer: B. An httpOnly, Secure cookie
httpOnly cookies cannot be read by injected scripts.
Which tool generates interactive docs from an OpenAPI file?
Show answer
Answer: A. Swagger UI
Swagger UI (or Scalar, Redoc) renders the spec with a “try it” console.
What does res.location() combined with res.status(201) achieve?
Show answer
Answer: B. Tells the client the URL of the new resource
The Location header points to the created resource.
Which logger writes fast structured JSON logs?
Show answer
Answer: A. pino
pino is a fast JSON logger; pino-http adds request logging.
Which variable typically switches Express into production behaviour?
Show answer
Answer: A. NODE_ENV=production
Express and many libraries optimise when NODE_ENV is production.
The payload of a JWT is encrypted, so it is safe to put a password in it.
Show answer
Answer: B. False
JWT payloads are only base64url-encoded and signed. Anyone with the token can read them.
From the lesson: JWTA logged-in student tries to delete a course reserved for admins. Which status code fits?
Show answer
Which function checks a token’s signature and expiry?
Show answer
Which URL is the most RESTful way to delete course 7?
Show answer
Answer: C. DELETE /api/courses/7
Method = verb, URL = resource.
From the lesson: REST API FundamentalsWhat does “stateless” mean in REST?
Show answer
Answer: B. Each request contains everything needed; the server keeps no per-client session between requests
Any server instance can handle any request.
From the lesson: REST API Fundamentals