In Node.js, the uncaughtExceptionMonitor event is triggered when an uncaughtException event occurs and there is no exception handler to handle it.

  • error handler
  • event listener
  • exception catcher
  • error catcher
Error Handling in Node.js

You are developing a complex application where each module has several dependencies. How would you structure your tests in Mocha to ensure that each module is tested in isolation?

  • Before each test, stub or mock the dependencies to isolate the module being tested.
  • Use only integration tests to ensure dependencies are properly integrated.
  • Test each module separately but don't worry about dependencies.
  • Test modules with real dependencies to ensure accurate results.
To ensure isolation, you should stub or mock the dependencies of each module before each test in Mocha. This prevents external factors from affecting the test results. The other options do not promote isolation, which is crucial for unit testing.

How does the lexical scoping mechanism work in JavaScript?

  • It allows functions to access variables defined in their caller's scope.
  • It restricts variables to the global scope only.
  • It enforces strict mode in JavaScript.
  • It determines the order of function execution.
Lexical scoping in JavaScript allows functions to access variables from their containing or parent scopes. This means that inner functions can access variables defined in outer functions, but not vice versa. The other options do not accurately describe lexical scoping.

Which npm script is automatically run when the npm publish command is executed?

  • prepublish
  • postpublish
  • prepublishOnly
  • prepare
The prepublishOnly script is automatically run when the npm publish command is executed. This script allows you to perform actions before the package is prepared for publication. It's commonly used for tasks like running tests or building production-ready code before publishing.

How can using Content Delivery Networks (CDNs) contribute to the performance optimization of web applications?

  • A CDN improves web application performance by serving content from a centralized server.
  • CDNs can execute JavaScript code more efficiently.
  • CDNs reduce the need for encryption in web applications.
  • CDNs automatically optimize database queries.
Content Delivery Networks (CDNs) contribute to web application performance optimization by caching and serving static content from edge servers located closer to the user. This reduces latency and offloads the main server, leading to faster load times. The other options are not accurate descriptions of CDN benefits.

Which statement is true regarding the order of executing imported and exporting modules?

  • Exported modules are always executed before imported modules.
  • Imported modules are executed first, followed by the execution of exported modules.
  • The order of execution depends on the module loader and cannot be determined.
  • Imported and exported modules are executed simultaneously.
In Node.js, when a module is imported, its code is executed immediately. Therefore, imported modules are executed first, and then the importing module's code continues to execute. This order ensures that the imported module's functionality is available to the importing module.

You are building a chat application and need to implement a feature to upload and download files. How would you use streams in Node.js to handle file transfers efficiently between the client and the server?

  • Read the entire file into memory on the server, then send it to the client in one go.
  • Stream the file from the client to the server using a Readable stream, and then save it to disk on the server using a Writable stream.
  • Use HTTP GET and POST requests to send files between the client and server.
  • Compress the file before transferring it to reduce bandwidth usage.
To efficiently handle file transfers in a chat application, you should stream the file from the client to the server using a Readable stream and then save it to disk on the server using a Writable stream. This approach avoids loading the entire file into memory and is suitable for large file transfers.

In Node.js, a duplex stream combines both readable and writable streams, and data can be written to and read from the '______' side.

  • input
  • output
  • read
  • write
In Node.js, a duplex stream combines both readable and writable streams, and data can be written to and read from the 'output' side. Duplex streams allow bidirectional data flow, making them suitable for tasks where data needs to be both read and written.

Which type of index is most suitable for searching through text-based content in a database?

  • Full-Text Index
  • B-Tree Index
  • Hash Index
  • Bitmap Index
Full-Text Index is the most suitable index type for searching through text-based content in a database. It is optimized for text search queries, allowing for efficient searching of words and phrases within text fields. B-Tree, Hash, and Bitmap indexes are more appropriate for different types of data and queries.

When chaining Promises, returning a non-Promise value from a .then() handler will cause the next .then() in the chain to receive a Promise resolved with that ________.

  • Error
  • Value
  • Promise
  • Rejection
When you return a non-Promise value (a regular value) from a .then() handler, the next .then() in the chain will receive a Promise that is resolved with that value. This allows you to pass values between Promise chain steps.