
















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The PrepIQ OpenJS Node.js Services Developer JSNSD Ultimate Exam focuses on building scalable backend services using Node.js. Coverage includes APIs, microservices, security, performance optimization, testing, deployment, and service integration.
Typology: Exams
1 / 56
This page cannot be seen from the preview
Don't miss anything!

















































Question 1. Which of the following statements best describes the role of the Node.js event loop? A) It executes JavaScript code in parallel threads. B) It manages asynchronous callbacks on a single thread. C) It compiles JavaScript to native machine code before execution. D) It provides garbage collection for V8. Answer: B Explanation: The event loop continuously checks the callback queue and processes asynchronous callbacks on Node’s single-threaded JavaScript thread. Question 2. In a Node.js application, which core module would you use to create an HTTP server? A) net B) url C) http D) fs Answer: C Explanation: The http core module supplies methods like createServer to handle HTTP requests and responses. Question 3. Which of the following is NOT a valid way to export functionality from a Node.js module? A) module.exports = function(){}; B) exports.myFunc = () => {}; C) export default function() {}; D) module.exports.myObj = {}; Answer: C
Explanation: export syntax belongs to ES modules; the question refers to CommonJS, where export is invalid. Question 4. When using the fs.readFile method, which argument order is correct? A) path, callback, encoding B) encoding, path, callback C) path, encoding, callback D) callback, path, encoding Answer: C Explanation: fs.readFile(path, encoding, callback) reads a file with optional encoding before invoking the callback. Question 5. Which of the following best explains why Node.js is well-suited for I/O-bound workloads? A) It uses multiple processes for each request. B) Its single-threaded nature eliminates context switching. C) Asynchronous, non-blocking I/O prevents the thread from waiting. D) Node.js compiles all I/O operations to native code. Answer: C Explanation: Non-blocking I/O lets the event loop continue handling other work while I/O operations complete. **Question 6. In Express.js, what does the next function do inside a middleware? ** A) Sends a response to the client. B) Terminates the request-response cycle.
Question 9. When constructing a RESTful API, which HTTP method should be used to partially update a resource? A) POST B) PUT C) PATCH D) DELETE Answer: C Explanation: PATCH applies partial modifications, whereas PUT replaces the entire resource. Question 10. In a Node.js microservice architecture, which pattern helps avoid tight coupling between services? A) Monolithic design B) Direct function calls C) Message queue (e.g., RabbitMQ) D) Shared global variables Answer: C Explanation: Message queues enable asynchronous, decoupled communication between services. Question 11. Which npm package is most commonly used for input validation in Express routes? A) lodash B) joi C) moment D) async Answer: B
Explanation: joi provides a declarative schema-based validation API suitable for request payloads. Question 12. What does the cluster module enable in a Node.js application? A) Automatic load balancing across multiple cores. B) Distributed caching across servers. C) Real-time database replication. D) Encryption of HTTP traffic. Answer: A Explanation: cluster spawns worker processes that share the same port, allowing multi-core utilization. Question 13. Which of the following statements about streams is FALSE? A) A readable stream can be piped into a writable stream. B) Streams reduce memory usage by handling data chunk-by-chunk. C) All streams are duplex by default. D) The pipe method handles back-pressure automatically. Answer: C Explanation: Only duplex streams are both readable and writable; readable or writable streams alone are not duplex. Question 14. In Node.js, which method creates a readable stream from a file? A) fs.createWriteStream() B) fs.openSync() C) fs.createReadStream() D) fs.readFileSync()
B) Access-Control-Allow-Origin: * C) X-Requested-With: * D) Content-Type: * Answer: B Explanation: Access-Control-Allow-Origin: * tells browsers that any origin may access the resource. Question 18. In a Node.js service using JWT for authentication, which claim typically contains the user’s unique identifier? A) exp B) iat C) sub D) aud Answer: C Explanation: The sub (subject) claim represents the principal that the token refers to, often a user ID. Question 19. Which of the following tools is most appropriate for automating API testing of a Node.js service? A) Mocha B) Postman/Newman C) ESLint D) Webpack Answer: B Explanation: Postman collections run via Newman provide end-to-end HTTP request testing.
Question 20. Which of the following statements about Node.js’s process.nextTick() is TRUE? A) It schedules a callback after the current poll phase completes. B) It runs callbacks after all I/O events have been processed. C) It executes the callback before any I/O timers in the same loop iteration. D) It is deprecated and should not be used. Answer: C Explanation: process.nextTick callbacks are placed at the front of the next tick queue, executing before I/O and timers. Question 21. When deploying a Node.js service with Docker, which instruction copies the application code into the image? A) RUN npm install B) COPY. /app C) EXPOSE 3000 D) CMD ["node","app.js"] Answer: B Explanation: COPY transfers files from the host context into the container’s filesystem. Question 22. Which npm script command runs a Node.js app with automatic restart on file changes? A) npm start B) npm run dev C) npm run watch D) npm run reload Answer: B (assuming the script is defined as dev using nodemon)
C) const fetchData = async() => {} D) Both B and C Answer: D Explanation: Both async function fetchData(){} and const fetchData = async () => {} create async functions returning promises. Question 26. Which of the following is NOT a built-in Node.js debugging tool? A) inspector B) console.log C) node --inspect D) chrome-devtools Answer: B Explanation: console.log is a logging method, not a dedicated debugging protocol; the others are part of Node’s debugging suite. Question 27. When using the axios library in a Node.js service, how can you set a request timeout of 5 seconds? A) axios.timeout(5000) B) axios({ timeout: 5000 }) C) axios.defaults.timeout = 5000 D) Both B and C Answer: D Explanation: You can pass timeout in the request config or set a default on axios.defaults. Question 28. Which of the following statements about the EventEmitter class is FALSE?
A) It can have unlimited listeners unless a limit is set. B) Emitting an event without listeners throws an error. C) Listeners can be removed with removeListener. D) once registers a listener that auto-removes after one call. Answer: B Explanation: Emitting an event with no listeners is a no-op; it does not raise an exception. Question 29. In a microservice built with Node.js, which pattern is used to propagate request-scoped data (e.g., correlation IDs) across async boundaries? A) Global variables B) AsyncLocalStorage C) Process.env D) Thread-local storage Answer: B Explanation: AsyncLocalStorage (Node 13+) maintains context across asynchronous calls. Question 30. Which of the following is the primary benefit of using a reverse proxy like Nginx in front of a Node.js service? A) Enables multi-threaded JavaScript execution. B) Provides TLS termination, load balancing, and static asset serving. C) Converts JavaScript to TypeScript at runtime. D) Allows direct database connections from the client. Answer: B Explanation: Nginx handles SSL, distributes traffic, and serves static files, offloading work from Node.
Answer: B Explanation: util.promisify(fn) returns a version of fn that returns a promise instead of using a callback. Question 34. Which of the following is the most appropriate HTTP status code for a request that exceeds the server’s defined rate limit? A) 400 Bad Request B) 401 Unauthorized C) 429 Too Many Requests D) 503 Service Unavailable Answer: C Explanation: 429 signals that the client has sent too many requests in a given amount of time. Question 35. When using the sequelize ORM with Node.js, which method synchronously creates the database tables based on defined models? A) sequelize.sync() B) sequelize.createAll() C) sequelize.migrate() D) sequelize.build() Answer: A Explanation: sequelize.sync() checks models and creates or updates tables accordingly. Question 36. Which of the following best describes the purpose of the dotenv package? A) Encrypt environment variables.
B) Load variables from a .env file into process.env. C) Validate JSON payloads. D) Manage database migrations. Answer: B Explanation: dotenv reads a .env file and populates process.env at runtime. Question 37. In a Node.js API, which response header indicates the type of content being sent? A) Authorization B) Content-Type C) Accept-Encoding D) Cache-Control Answer: B Explanation: Content-Type tells the client the MIME type of the response body (e.g., application/json). Question 38. Which of the following is the correct way to handle unhandled promise rejections globally? A) process.on('unhandledRejection', handler) B) process.on('uncaughtException', handler) C) try { await promise } catch {} D) There is no global handler; each promise must be caught. Answer: A Explanation: The unhandledRejection event fires when a promise is rejected without a catch.
Explanation: TypeScript adds compile-time type safety, reducing runtime errors. **Question 42. Which of the following statements about process.hrtime() is TRUE? ** A) It returns the current time in milliseconds. B) It provides high-resolution real-time in nanoseconds as a tuple. C) It is deprecated in Node 14+. D) It can be used to set timers. Answer: B Explanation: process.hrtime() returns [seconds, nanoseconds] for high-resolution timing. Question 43. When using the winston logging library, which transport would you choose to log messages to a file? A) Console B) File C) Http D) MongoDB Answer: B Explanation: The File transport writes logs to a specified file on disk. Question 44. Which of the following is the correct way to create a child process that executes the ls -l command and streams its stdout to the parent? A) exec('ls -l') B) spawn('ls', ['-l']) C) fork('ls -l')
D) run('ls -l') Answer: B Explanation: spawn creates a new process with separate stdio streams, allowing real-time piping. Question 45. In an Express route, which method sends a JSON response and automatically sets the appropriate Content-Type header? A) res.send(JSON.stringify(data)) B) res.json(data) C) res.write(data) D) res.end(data) Answer: B Explanation: res.json serializes the object to JSON and sets Content-Type: application/json. Question 46. Which of the following is the primary purpose of the pm2 tool in Node.js deployments? A) Code linting B) Process management and clustering C) Database migration D) Front-end bundling Answer: B Explanation: pm2 starts, monitors, restarts, and clusters Node processes in production. Question 47. Which of the following best describes “circuit breaking” in the context of a Node.js service calling external APIs?
Question 50. Which of the following is the most suitable Node.js approach for implementing a real-time chat feature? A) Long polling with setInterval B) Server-Sent Events (SSE) only C) WebSockets using the ws or socket.io library D) HTTP/2 push streams Answer: C Explanation: WebSockets provide full-duplex communication ideal for real-time chat. Question 51. Which of the following statements about async/await error handling is correct? A) Errors thrown inside an async function are ignored. B) Use try/catch blocks around awaited calls to capture rejections. C) await automatically retries failed promises. D) async functions cannot return values. Answer: B Explanation: await propagates promise rejections as thrown errors, which can be caught with try/catch. Question 52. When configuring CORS in Express, which option allows credentials (cookies, auth headers) to be sent? A) origin: '*' B) credentials: true C) methods: ['GET'] D) exposedHeaders: []
Answer: B Explanation: Setting credentials: true permits browsers to include cookies and authorization headers in cross-origin requests. Question 53. Which of the following is the correct syntax to define a read-only property on an object using Object.defineProperty? A) Object.defineProperty(obj, 'prop', { value: 42, writable: false }); B) Object.defineProperty(obj, 'prop', { value: 42, readOnly: true }); C) Object.defineProperty(obj, 'prop', { get: () => 42 }); D) Both A and C Answer: D Explanation: Setting writable: false or providing only a getter makes the property read-only. Question 54. In a Node.js REST API, which HTTP status code should be returned when a client attempts to access a resource without proper authentication? A) 401 Unauthorized B) 403 Forbidden C) 400 Bad Request D) 404 Not Found Answer: A Explanation: 401 indicates that authentication is required or has failed. Question 55. Which of the following npm packages helps generate OpenAPI (Swagger) documentation from Express route definitions? A) swagger-jsdoc B) swagger-ui-express