





























































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 Application Developer JSNAD Ultimate Exam helps developers prepare for Node.js application development certification. Topics include JavaScript fundamentals, asynchronous programming, APIs, modules, testing, debugging, and application deployment.
Typology: Exams
1 / 69
This page cannot be seen from the preview
Don't miss anything!






























































Question 1. Which of the following statements best describes the purpose of the Node.js event loop? A) It compiles JavaScript code into native machine code. B) It continuously monitors and processes pending callbacks and I/O events. C) It creates a new thread for each incoming HTTP request. D) It manages memory allocation for V8. Answer: B Explanation: The event loop is the core mechanism that checks the callback queue and executes callbacks when the call stack is empty, enabling non-blocking I/O.
Question 2. In Node.js, which module provides utilities for working with file and directory paths? A) fs B) path C) url D) util Answer: B Explanation: The path module contains methods such as join, resolve, and basename to manipulate file system paths in a platform-independent way.
Question 3. What does the require('module').builtinModules array contain? A) Names of all third-party packages installed in node_modules.
B) Paths to all user-defined modules in the project. C) The list of modules that are compiled into Node.js core. D) Environment variables defined for the process. Answer: C Explanation: builtinModules returns an array of strings representing the names of Node.js core modules like fs, http, and crypto.
Question 4. Which of the following is the correct way to create an HTTP server that responds with “Hello World” using the built-in http module? A) http.createServer((req, res) => { res.end('Hello World'); }).listen(3000); B) http.listen(3000, (req, res) => { res.write('Hello World'); }); C) http.server((req, res) => { res.send('Hello World'); }).listen(3000); D) new http.Server((req, res) => { res.writeHead(200); res.end('Hello World'); }).listen(3000); Answer: A Explanation: http.createServer takes a request listener callback; calling listen starts the server. res.end finalizes the response.
Question 5. When using the fs.readFile asynchronous API, which argument order is correct? A) (path, encoding, callback) B) (callback, path, encoding) C) (path, callback, encoding)
Explanation: Calling next() tells Express to continue processing subsequent middleware functions; without it, the request may hang.
Question 8. Which HTTP status code indicates that the request was successful and a new resource was created? A) 200 B) 201 C) 202 D) 301 Answer: B Explanation: Status 201 (Created) is returned when a POST request results in the creation of a new resource.
Question 9. What is the effect of setting app.set('trust proxy', true) in an Express app? A) Express will ignore the X-Forwarded-Proto header. B) Express will treat the client’s IP address as the IP of the proxy. C) Express will respect the X-Forwarded-* headers when determining the original client’s connection info. D) Express will disable all proxy support. Answer: C Explanation: Enabling trust proxy tells Express to use the X-Forwarded-* headers to infer the original request protocol, host, and IP.
Question 10. Which of the following is the most appropriate way to prevent a Node.js application from crashing due to an uncaught exception? A) Wrap the entire application code in a try/catch block. B) Use process.on('uncaughtException', handler) to log and gracefully shut down. C) Ignore the error; Node.js will automatically recover. D) Set process.exit(1) at the top of the script. Answer: B Explanation: Listening for uncaughtException allows you to log the error and perform cleanup before exiting; it should not be used to keep the process running indefinitely.
Question 11. Which npm command installs a package and adds it to the dependencies section of package.json? A) npm install --save-dev B) npm install --save C) npm add D) npm install (without flags) Answer: D Explanation: Since npm 5, npm install automatically adds the package to dependencies. The --save-dev flag adds to devDependencies.
A) Each worker runs on a separate machine. B) Workers share the same event loop, improving concurrency. C) Workers can utilize multiple CPU cores, providing true parallelism. D) Workers automatically balance HTTP load without a load balancer. Answer: C Explanation: Forked workers run in separate processes, each with its own V instance, allowing Node.js to take advantage of multi-core CPUs.
Question 15. Which of the following is the correct way to define a read-only environment variable in a Node.js process? A) process.env.READ_ONLY = 'value'; B) Object.defineProperty(process.env, 'READ_ONLY', { value: 'value', writable: false }); C) const READ_ONLY = process.env.READ_ONLY; D) process.env.set('READ_ONLY', 'value'); Answer: B Explanation: Using Object.defineProperty can make a property non-writable, effectively creating a read-only environment variable at runtime.
Question 16. Which Node.js core module provides DNS resolution functions such as lookup and resolve4? A) net B) dns
C) http D) url Answer: B Explanation: The dns module offers methods for resolving hostnames to IP addresses and vice-versa.
Question 17. What is the default value of the maxListeners property for an EventEmitter instance? A) 0 (unlimited) B) 10 C) 100 D) 1 Answer: B Explanation: Node.js sets maxListeners to 10 to help detect potential memory leaks; it can be changed with emitter.setMaxListeners().
Question 18. Which of the following is a security risk when using eval() on user-provided strings in a Node.js application? A) It can cause memory leaks. B) It may block the event loop for a long time. C) It allows execution of arbitrary JavaScript code, leading to code injection. D) It disables the module cache.
Question 21. What does the --inspect flag enable when starting a Node.js application? A) Production-grade logging. B) Automatic code minification. C) Remote debugging via the Chrome DevTools protocol. D) Enabling experimental ES modules. Answer: C Explanation: --inspect opens a WebSocket endpoint that Chrome DevTools can connect to for debugging.
Question 22. Which HTTP header is most appropriate for preventing browsers from caching a JSON API response? A) Cache-Control: no-store B) Expires: 0 C) Pragma: no-cache D) ETag: * Answer: A Explanation: Cache-Control: no-store instructs browsers and intermediate caches not to store the response at all.
Question 23. When using async/await, what is the purpose of the try/catch block around an await expression? A) To convert a rejected promise into a resolved value. B) To handle exceptions thrown by the awaited promise. C) To force the event loop to pause until the promise resolves. D) To automatically retry the operation. Answer: B Explanation: If the awaited promise rejects, the rejection is thrown as an exception, which can be caught with try/catch.
Question 24. Which of the following is NOT a valid way to export multiple values from a CommonJS module? A) module.exports = { a, b }; B) exports.a = a; exports.b = b; C) module.exports = a; module.exports = b; D) module.exports = { a: a, b: b }; Answer: C Explanation: Assigning module.exports twice overwrites the previous export; only the last assignment is exported.
Question 25. In a Node.js REPL, what does the .clear command do?
C) It enables backpressure handling automatically for synchronous iterables only. D) It buffers the entire iterable in memory before emitting data. Answer: A Explanation: Readable.from takes any iterable or async iterable and turns it into a readable stream, emitting each item as a chunk.
Question 28. Which of the following is a correct way to handle uncaught promise rejections in a Node.js process? A) process.on('unhandledRejection', (reason, promise) => { /* log and exit */ }); B) process.on('uncaughtException', (err) => { /* log */ }); C) process.on('rejectionHandled', (promise) => { /* ignore */ }); D) process.on('error', (err) => { /* handle */ }); Answer: A Explanation: The unhandledRejection event is emitted when a promise is rejected and no .catch handler is attached.
Question 29. In Express, which method is used to serve static files from a directory named public? A) app.use(express.static('public')); B) app.static('public'); C) app.use('/static', express.static('public')); D) Both A and C are valid.
Answer: D Explanation: Both statements set up static file serving; the second example mounts it at the /static URL prefix.
Question 30. Which of the following statements about the worker_threads module is FALSE? A) Workers share the same event loop as the parent thread. B) Data is transferred between threads via MessagePort objects. C) Each worker has its own V8 instance and memory heap. D) Workers can be used to offload CPU-intensive tasks. Answer: A Explanation: Workers run in separate threads with independent event loops; they do not share the parent’s event loop.
Question 31. What does the crypto.randomBytes(16).toString('hex') call produce? A) A 16-character base64 string. B) A 32-character hexadecimal string representing 16 random bytes. C) A Buffer object containing 16 ASCII characters. D) A UUID version 4. Answer: B Explanation: randomBytes(16) generates 16 random bytes; converting to 'hex' yields a 32-character hexadecimal representation.
Question 34. Which of the following HTTP verbs is idempotent but not safe? A) GET B) POST C) PUT D) HEAD Answer: C Explanation: PUT can be called multiple times with the same payload without changing the result (idempotent), but it modifies server state (not safe).
Question 35. In a RESTful API, which status code is most appropriate when a client sends a request with missing required fields? A) 400 Bad Request B) 401 Unauthorized C) 403 Forbidden D) 422 Unprocessable Entity Answer: A Explanation: 400 indicates the request is syntactically incorrect or missing required information.
Question 36. Which of the following Node.js APIs can be used to watch for changes in a file or directory?
A) fs.watchFile B) fs.watch C) Both A and B D) fs.monitor Answer: C Explanation: Both fs.watch and fs.watchFile provide file-system watching capabilities, though they differ in implementation and performance.
Question 37. What is the purpose of the helmet middleware in an Express application? A) To enable CORS for all routes. B) To provide a set of security-related HTTP headers. C) To compress responses automatically. D) To log request details to a file. Answer: B Explanation: helmet sets various HTTP headers (e.g., Content-Security-Policy, X-Frame-Options) to help protect against common web vulnerabilities.
Question 38. Which of the following statements about the process.nextTick function is TRUE? A) It schedules a callback to run after all I/O events in the current phase. B) It runs the callback immediately, before any I/O or timer callbacks.
Explanation: express.json() limits the parsed JSON payload to 1 MB unless configured otherwise.
Question 41. What does the npm ci command do that npm install does not? A) Installs only devDependencies. B) Performs a clean install using the exact versions from package-lock.json. C) Generates a new package-lock.json. D) Runs the project's test suite after installation. Answer: B Explanation: npm ci removes node_modules and installs exactly what is described in package-lock.json, providing reproducible builds.
Question 42. Which of the following describes a “memory leak” in a long-running Node.js process? A) The V8 garbage collector fails to free objects that are no longer reachable. B) The event loop stops processing callbacks. C) The process runs out of file descriptors. D) All promises remain pending forever. Answer: A Explanation: A memory leak occurs when retained references prevent the garbage collector from reclaiming memory, causing gradual growth.
Question 43. When configuring CORS in Express with the cors package, which option enables credentials (cookies, HTTP authentication) to be sent? A) origin: true B) methods: ['GET','POST'] C) credentials: true D) exposedHeaders: ['X-My-Header'] Answer: C Explanation: Setting credentials: true adds the Access-Control-Allow-Credentials header, allowing browsers to include cookies and auth headers.
Question 44. Which of the following is a valid way to create a promise that resolves after 2 seconds? A) new Promise((res) => setTimeout(res, 2000)); B) Promise.delay(2000); C) setTimeout(() => Promise.resolve(), 2000); D) Promise.timeout(2000); Answer: A Explanation: The constructor receives a resolver; calling setTimeout(res, 2000) resolves the promise after the delay.