In Node.js, Buffer instances are representations of fixed-length sequences of bytes. When accessing a buffer element by index, it returns the numeric ASCII/UTF-8 byte value (104 for lowercase 'h').
Question 2 · Scaling · junior
What is the primary purpose of the cluster module in Node.js?
A.To convert callback-based asynchronous code into native Promises.
B.To take advantage of multi-core systems by spawning worker processes that share the same server port.
C.To manage environment variables across different deployment stages.
D.To synchronize data between multiple remote database servers.
Show answer
B. To take advantage of multi-core systems by spawning worker processes that share the same server port.
The cluster module enables the creation of child processes (workers) that all share the same server port, allowing Node.js applications to scale across multiple CPU cores for better throughput and reliability.
Question 3 · Module System · junior
What do __dirname and __filename represent in a Node.js module?
console.log(__dirname);
console.log(__filename);
A.Environment variables loaded from a .env configuration file.
B.Global browser variables that return window metadata.
C.CommonJS wrapper variables providing the directory path and file path of the current module.
D.Constants imported automatically from the operating system module.
Show answer
C. CommonJS wrapper variables providing the directory path and file path of the current module.
__dirname represents the directory name of the current module, and __filename represents the full file path of the current module. These are wrapper variables provided by Node.js for each module.