Node.js Communication & Stakeholder Relations 5 — Questions and Answers
Question 1: A stakeholder escalates that your Node.js API's error messages expose internal file paths. What is the correct fix?
- Disable error handling entirely
- Catch errors and return sanitized messages in production, stripping stack traces from responses (Correct answer)
- Log paths to the database instead
- Move files to hide the path names
Correct answer: Catch errors and return sanitized messages in production, stripping stack traces from responses
In production, middleware should catch errors and return generic messages, with full stack traces written only to server-side logs.
Question 2: Your team is adopting GraphQL subscriptions in Node.js. How do you explain the communication model to a REST-accustomed stakeholder?
- It's like REST but slower
- Subscriptions maintain a persistent connection (via WebSocket) and push data to clients when server-side events occur (Correct answer)
- Clients must poll the GraphQL endpoint repeatedly
- Subscriptions only work over gRPC
Correct answer: Subscriptions maintain a persistent connection (via WebSocket) and push data to clients when server-side events occur
GraphQL subscriptions use WebSocket connections to push real-time updates to subscribed clients when relevant data changes.
Question 3: A team lead wants to ensure Node.js service errors are centrally tracked. Which integration is the industry standard?
- Write errors to a local .txt file
- Integrate an error tracking service like Sentry using its Node.js SDK to capture and report exceptions (Correct answer)
- Email the error stack to the team
- Store errors in localStorage
Correct answer: Integrate an error tracking service like Sentry using its Node.js SDK to capture and report exceptions
Sentry and similar APM tools automatically capture, group, and alert on Node.js exceptions with full context, enabling rapid response.
Question 4: A client integration requires your Node.js service to support CORS for cross-origin browser requests. What do you implement?
- Disable HTTPS to avoid CORS
- Use the 'cors' npm middleware to set appropriate Access-Control-Allow-Origin headers (Correct answer)
- Proxy all client requests through the server
- Tell clients to disable CORS in their browser
Correct answer: Use the 'cors' npm middleware to set appropriate Access-Control-Allow-Origin headers
The 'cors' package configures CORS headers to permit specific or all origins, enabling browser-based cross-origin API access.
Question 5: A project manager asks how your Node.js service handles a downstream API that's temporarily unavailable. What pattern best communicates resilience?
- The service crashes and restarts
- The circuit breaker pattern — after N failures the service fast-fails and retries after a cooldown period (Correct answer)
- Requests queue indefinitely until the API recovers
- All requests return HTTP 200 regardless
Correct answer: The circuit breaker pattern — after N failures the service fast-fails and retries after a cooldown period
The circuit breaker pattern prevents cascade failures by short-circuiting calls to failing dependencies and allowing recovery time.
Question 6: You need to communicate API rate limits to client developers. Which HTTP headers should your Node.js API return?
- X-Powered-By and Server
- X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset (Correct answer)
- Content-Length and ETag
- Authorization and WWW-Authenticate
Correct answer: X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset
X-RateLimit headers are the de facto standard for communicating rate limit status to API consumers per IETF draft conventions.
Question 7: A new developer joins the team and needs to understand how your Node.js service's modules communicate internally. Which pattern describes a service using EventEmitter vs. direct function calls?
- EventEmitter is synchronous; direct calls are asynchronous
- EventEmitter decouples producers from consumers so emitters don't need to know their listeners; direct calls create tight coupling (Correct answer)
- They are equivalent in all ways
- EventEmitter only works across network boundaries
Correct answer: EventEmitter decouples producers from consumers so emitters don't need to know their listeners; direct calls create tight coupling
EventEmitter implements the observer pattern, decoupling event producers from consumers and enabling loose coupling within a Node.js process.
A stakeholder escalates that your Node.js API's error messages expose internal file paths.
What is the correct fix?