Interview Q&A / Node.js
Node.js interview questions
The event loop on the server, streams, modules and building APIs with Express.
Prefer rapid revision? Practise Node.js short interview answers →
- What are good URL naming conventions for REST resources?
Use plural nouns for resources, let the HTTP method express the action, nest only one level for relationships, and use lowercase with hyphens. So GET /students/5/courses, not /getStudentCourses?id=5.
BeginnerQuick answer1 min read - What is the difference between PUT and PATCH in a REST API?
PUT replaces the whole resource with the body you send, so missing fields are cleared. PATCH changes only the fields you send. PUT is idempotent by definition; PATCH is not guaranteed to be.
BeginnerQuick answer1 min read - Which HTTP status codes should a REST API return for create, validation errors, missing login and forbidden access?
201 Created for a successful create, 400 for bad input (or 422 for failed validation), 401 when the user is not authenticated, 403 when authenticated but not allowed, 404 for a missing resource, and 500 for server faults.
BeginnerQuick answer1 min read - How do you version a REST API, and why would you?
Versioning lets you change the API without breaking existing clients. The common way is a URL prefix such as /api/v1. Other options are a custom header or media type. Avoid breaking changes inside a version.
IntermediateQuick answer1 min read - How should a REST API return error responses consistently?
Use one JSON shape for every error with the right HTTP status, a stable machine-readable code, a human message, and optional field details. Never leak stack traces or database errors to clients.
IntermediateQuick answer1 min read - How would you design pagination for an API endpoint that returns thousands of records?
Return a slice per request using limit and page (offset) or, for large changing data, a cursor of the last item seen. Cap the maximum limit and return total or next-page information in the response.
IntermediateQuick answer1 min read - What does idempotent mean for HTTP methods, and which methods are idempotent?
An idempotent request has the same effect on the server whether it is sent once or many times. GET, PUT, DELETE, HEAD and OPTIONS are idempotent; POST is not, and PATCH may not be.
IntermediateQuick answer1 min read