






































































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
This exam certifies advanced Node.js development skills for Chinese professionals. Candidates are tested on Node.js runtime, asynchronous programming, modules, event-driven architecture, RESTful API development, testing, debugging, and deployment. Passing demonstrates proficiency in building scalable, maintainable Node.js applications.
Typology: Exams
1 / 78
This page cannot be seen from the preview
Don't miss anything!







































































Question 1. Which of the following statements about async/await is TRUE? A) await can only be used inside a regular function. B) await pauses the entire Node.js event loop. C) await always returns the resolved value of a promise or throws the rejection. D) await converts a callback-based function automatically to a promise. Answer: C Explanation: await pauses the async function until the promise settles, returning its resolved value or throwing the rejection, without blocking the event loop. Question 2. What does Promise.allSettled([p1, p2]) return? A) An array of resolved values only. B) An array of rejection reasons only. C) An array of objects describing each promise’s status and value or reason. D) The first promise that settles. Answer: C Explanation: Promise.allSettled resolves after all input promises settle, providing an object for each with {status: "fulfilled", value} or {status: "rejected", reason}. Question 3. In the Node.js event loop, which queue processes microtasks? A) Timers queue. B) I/O callbacks queue. C) Check queue. D) Microtask queue (process.nextTick and Promise jobs). Answer: D Explanation: Microtasks (process.nextTick and Promise jobs) run after each phase, before the next event-loop tick, ensuring they execute before macrotasks. Question 4. Which of the following correctly demonstrates block-level scope with let? A) if (true) { var x = 10; } console.log(x);
B) if (true) { let y = 20; } console.log(y); C) for (let i = 0; i < 3; i++) {} console.log(i); D) function f() { let z = 5; } console.log(z); Answer: B Explanation: let is block-scoped; y exists only inside the if block, so console.log(y) would throw a ReferenceError, illustrating proper block scope. Question 5. What does the spread operator (...) do when used in object literals? A) Copies prototype chain properties. B) Merges enumerable own properties of the source object into the new object. C) Converts the object to an array. D) Creates a deep clone of nested objects. Answer: B Explanation: {...obj} copies all enumerable own properties of obj into a new object (shallow copy). **Question 6. Which template literal tag can be used to escape HTML characters? ** A) String.raw B) htmlEscape (custom) C) String.uppercase D) String.trim Answer: B Explanation: A custom tag function like htmlEscape can process template literal substitutions to escape HTML; built-in tags do not perform this automatically. Question 7. How does the value of this behave in an arrow function? A) It is bound to the global object. B) It is dynamically scoped based on how the function is called. C) It inherits this from the surrounding lexical context.
Explanation: Assigning to module.exports defines what other files receive when they require this module. Question 11. What is the result of requiring the same module multiple times in Node.js? A) The module code runs each time. B) Node creates a new instance for each require. C) The cached exports object is returned after the first load. D) An error is thrown for duplicate loads. Answer: C Explanation: Node caches the module after the first evaluation; subsequent require calls return the cached exports. Question 12. Which statement correctly imports the default export from an ES module named utils.mjs? A) import utils from './utils.mjs'; B) const utils = require('./utils.mjs'); C) import * as utils from './utils.mjs'; D) export default utils from './utils.mjs'; Answer: A Explanation: import utils from './utils.mjs' imports the default export; * as imports all named exports. Question 13. How can a CommonJS module import an ES module that uses export default? A) import foo from './esm.mjs'; B) require('./esm.mjs').default C) require('./esm.mjs') directly returns the default. D) It is not possible. Answer: B Explanation: When a CJS file requires an ESM, the default export is available under the .default property.
Question 14. In an ES module, why are __dirname and __filename undefined? A) They are replaced by import.meta.url. B) They are only available in the REPL. C) They are removed for security reasons. D) They are still available but need a flag. Answer: A Explanation: ES modules use import.meta.url to obtain the module’s URL; __dirname and __filename are not defined. Question 15. Which field in package.json specifies the command to run the test suite? A) "scripts": {"test": "mocha"}" B) "devDependencies" C) "main" D) "engines" Answer: A Explanation: The scripts object defines shortcut commands; "test" is the conventional name for the test script. Question 16. What does the package-lock.json file primarily ensure? A) That the same versions of dependencies are installed across environments. B) That the project runs only on Linux. C) That all modules are bundled into a single file. D) That the node_modules folder is ignored by Git. Answer: A Explanation: package-lock.json locks the exact versions (including transitive dependencies) to guarantee reproducible installs. Question 17. How do you allocate a zero-filled Buffer of length 10? A) Buffer.alloc(10) B) new Buffer(10)
Explanation: The 'data' event provides a chunk each time the stream has data ready to be consumed. Question 21. What is backpressure in the context of Writable streams? A) When a stream writes data faster than the destination can handle, causing write() to return false. B) When the OS runs out of file descriptors. C) When the event loop is blocked by CPU-intensive code. D) When a stream emits an 'error' event. Answer: A Explanation: Backpressure signals that the consumer cannot keep up; Writable streams return false and emit 'drain' when they are ready again. Question 22. Which utility function safely pipes multiple streams and forwards errors? A) stream.pipe() B) stream.pipeline() C) stream.concat() D) stream.chain() Answer: B Explanation: stream.pipeline (Node 10+) connects streams and automatically handles cleanup and error propagation. Question 23. How do you create a custom EventEmitter subclass named MyEmitter? A) class MyEmitter extends EventEmitter {} B) function MyEmitter() {} C) const MyEmitter = new EventEmitter(); D) class MyEmitter {} Answer: A Explanation: Extending the built-in EventEmitter class creates a subclass that inherits event-handling capabilities.
**Question 24. Which method removes a specific listener from an EventEmitter? ** A) emitter.off(event, listener) (Node 10+) B) emitter.delete(event, listener) C) emitter.removeAllListeners(event) D) emitter.clear(event) Answer: A Explanation: emitter.off (or the older removeListener) detaches a particular listener for the given event. Question 25. What does util.promisify(fs.readFile) return? A) A synchronous version of readFile. B) A function that returns a Promise resolving with the file data. C) An object with readFile as a property. D) It throws an error because fs.readFile is already promise-based. Answer: B Explanation: util.promisify converts a callback-style function into one that returns a Promise. Question 26. Which pattern runs asynchronous tasks in parallel and waits for all to finish? A) for await...of loop. B) Promise.all([...]). C) Sequential await statements. D) setImmediate callbacks. Answer: B Explanation: Promise.all starts all promises concurrently and resolves when every promise fulfills. Question 27. Which fs method reads a file synchronously? A) fs.readFile() B) fs.readFileSync()
Answer: B Explanation: path.resolve processes the segments, normalizing .. to move up one level, resulting in /home/user/b. Question 31. Which process property provides access to command-line arguments? A) process.argv B) process.env C) process.execArgv D) process.args Answer: A Explanation: process.argv is an array containing the node executable, script name, and any additional arguments. Question 32. How can a Node.js script read environment variable PORT with a fallback to 3000? A) process.env.PORT || 3000 B) process.env['PORT'] ?? 3000 (both work) C) process.getEnv('PORT', 3000) D) process.env.PORT? process.env.PORT : 3000 Answer: A Explanation: process.env.PORT returns undefined if not set; the logical OR provides the default. Question 33. Which method sends data to the parent process from a child spawned with fork()? A) child.send(message) B) process.stdout.write(message) C) child.emit('message', message) D) process.ipc(message) Answer: A Explanation: In a forked process, process.send (in child) and child.send (in parent) communicate via IPC channels.
Question 34. What does the CLI flag --inspect enable? A) ECMAScript module support. B) Debugging via the V8 inspector protocol. C) Automatic code formatting. D) Strict mode enforcement. Answer: B Explanation: --inspect opens a debugging port that Chrome DevTools or other inspectors can connect to. Question 35. Which of the following is an operational error? A) ReferenceError: x is not defined B) SyntaxError: Unexpected token C) ENOENT: no such file or directory when reading a missing file. D) TypeError: Cannot read property 'foo' of undefined Answer: C Explanation: Operational errors arise from external conditions (e.g., missing file) and are expected to be handled gracefully. Question 36. How can you globally catch unhandled promise rejections? A) process.on('uncaughtException', handler) B) process.on('unhandledRejection', handler) C) process.on('error', handler) D) process.on('rejectionHandled', handler) Answer: B Explanation: The 'unhandledRejection' event fires when a promise is rejected and no handler is attached. Question 37. Which built-in module provides assertion methods for testing? A) node:test B) assert (or node:assert)
Explanation: execFile directly executes a binary without a shell, reducing overhead and avoiding shell interpolation; spawn can optionally use a shell via the shell option. Question 41. Which signal is emitted when a user presses Ctrl-C in the terminal? A) SIGTERM B) SIGKILL C) SIGINT D) SIGHUP Answer: C Explanation: SIGINT (interrupt) is sent to the process on Ctrl-C. Question 42. How can a Node.js process exit with status code 2? A) process.exit(2) B) process.kill(2) C) process.abort(2) D) process.terminate(2) Answer: A Explanation: process.exit(code) terminates the process with the given exit code. Question 43. What does process.nextTick() do? A) Schedules a callback after the current event-loop phase but before any I/O callbacks. B) Executes the callback immediately, blocking the loop. C) Defers the callback to the next macro-task. D) Creates a new thread for the callback. Answer: A Explanation: process.nextTick queues a microtask that runs after the current operation completes, before other I/O events.
Question 44. Which method of the fs module returns a FileHandle object for use with async iteration? A) fs.openSync B) fs.promises.open C) fs.createReadStream D) fs.readFile Answer: B Explanation: fs.promises.open resolves to a FileHandle which provides async iterator methods like read(). Question 45. When using fs.createReadStream, which option controls the size of each data chunk? A) highWaterMark B) bufferSize C) chunkSize D) maxChunk Answer: A Explanation: highWaterMark sets the internal buffer threshold that determines when 'data' events are emitted. Question 46. Which method on a Transform stream is used to implement custom data manipulation? A) _read B) _write C) _transform D) _flush Answer: C Explanation: Implementing _transform(chunk, encoding, callback) allows the stream to modify or process incoming data. Question 47. In a pipeline of streams, which event signals that the pipeline completed without error? A) 'finish' on the last Writable stream.
D) Use process.nextTick after writing. Answer: A Explanation: stream.end() signals no more data; the 'finish' event indicates all buffered data has been flushed. Question 51. Which built-in module provides utilities for working with binary data, such as converting numbers to buffers? A) crypto B) buffer C) util D) stream Answer: B Explanation: The buffer module defines the Buffer class and related methods for binary data handling. Question 52. What does the highWaterMark option of a Writable stream control? A) The maximum number of listeners allowed. B) The threshold at which write() returns false to apply backpressure. C) The size of the internal event queue. D) The amount of memory allocated for the stream’s metadata. Answer: B Explanation: When the internal buffer exceeds highWaterMark, write() returns false, indicating the need to wait for 'drain'. Question 53. Which method can be used to delete a directory recursively in Node 14+? A) fs.rmdirSync(path, { recursive: true }) B) fs.rmSync(path, { recursive: true }) (Node 16+) C) fs.unlinkSync(path, { recursive: true }) D) fs.deleteSync(path, { recursive: true }) Answer: A
Explanation: fs.rmdirSync with { recursive: true } removes a directory and its contents (deprecated in newer versions but still valid for Node 14). Question 54. How does path.normalize() treat redundant .. and . segments? A) It removes them and resolves the path to a canonical form. B) It leaves them unchanged. C) It throws an error if .. attempts to go above the root. D) It converts them to URL-encoded characters. Answer: A Explanation: normalize resolves . and .. and collapses duplicate separators, producing a clean path string. Question 55. Which process event is emitted when the event loop has no more work to perform? A) 'exit' B) 'beforeExit' C) 'idle' D) 'shutdown' Answer: B Explanation: 'beforeExit' fires when Node has emptied the event loop but before the process actually exits, allowing asynchronous work. Question 56. In a child process created with spawn, how can you capture its stdout line by line? A) Set stdio: 'pipe' and listen to child.stdout.on('data', ...) converting buffers to strings. B) Use child.stdout.read() inside a loop. C) Set stdio: 'inherit'. D) Use child.stdout.on('line', ...). Answer: A
Question 60. How can you import only the readFile function from the fs/promises module? A) import { readFile } from 'fs/promises'; B) const { readFile } = require('fs/promises'); C) import readFile from 'fs/promises'; D) import * as readFile from 'fs/promises'; Answer: A Explanation: Named import syntax { readFile } pulls the specific export from the ES module. Question 61. Which method of the fs module can be used to atomically replace a file's contents? A) fs.rename after writing to a temporary file. B) fs.writeFile with the atomic flag. C) fs.copyFile with COPYFILE_EXCL. D) fs.truncate followed by fs.appendFile. Answer: A Explanation: Writing to a temporary file and then renaming it (fs.rename) provides an atomic replacement because rename is atomic on most file systems. Question 62. What does process.env.NODE_DEBUG='fs' enable? A) Debug output for the fs module. B) Strict mode for file system operations. C) Automatic retries on failed I/O. D) Logging of all environment variables. Answer: A Explanation: Setting NODE_DEBUG to a module name prints internal debug messages for that module. Question 63. Which of the following correctly creates a readable stream from a string without using a file? A) new stream.Readable({ read() { this.push(str); this.push(null); } })
B) fs.createReadStream(str) C) stream.from(str) (non-existent) D) stream.string(str) Answer: A Explanation: Subclassing Readable and implementing read to push the string and then null creates a stream from in-memory data. Question 64. How does Promise.race([p1, p2]) behave? A) Resolves when both promises have settled. B) Resolves or rejects as soon as the first promise settles. C) Ignores rejections and only resolves with the first fulfillment. D) Returns an array of results. Answer: B Explanation: Promise.race settles with the outcome of the first promise that settles, whether fulfilled or rejected. Question 65. Which of the following is true about arrow functions and the arguments object? A) Arrow functions have their own arguments object. B) Arrow functions inherit arguments from the nearest non-arrow function. C) Arrow functions throw an error when arguments is accessed. D) arguments is always undefined inside arrow functions. Answer: B Explanation: Arrow functions do not have their own arguments; they close over the arguments of the surrounding function. Question 66. Which method from the util module can be used to format a string with placeholders? A) util.format B) util.inspect C) util.promisify D) util.types