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.

What is the outcome of using closures regarding variable scope and lifetime in JavaScript?

  • Variables declared in a closure have global scope.
  • Variables declared in a closure are accessible only within the closure itself.
  • Variables declared in a closure have the same scope as variables declared in the outer function.
  • Variables declared in a closure have function scope.
Closures in JavaScript have function scope, meaning variables declared within a closure are accessible only within that closure. They do not have global scope and are not directly accessible from outside the closure.

How can you access environment variables in a Node.js application using the process object?

  • process.env.MY_VARIABLE
  • Node.env.get("MY_VARIABLE")
  • global.MY_VARIABLE
  • env.process.MY_VARIABLE
In a Node.js application, you can access environment variables using process.env.MY_VARIABLE. The process object provides access to environment variables, and you access them using dot notation. The other options are incorrect syntax or reference non-existent objects.

The npm start command will run the script specified under the ______ key in the package.json file.

  • start
  • main
  • scripts
  • run
The npm start command runs the script specified under the "scripts" key in the package.json file. This key typically contains an object with various script names and their associated commands.

To enable debugging in an Express app, you should set the DEBUG environment variable to ______.

  • TRUE
  • FALSE
  • 1
  • 'express:debug'
To enable debugging in an Express app, you should set the DEBUG environment variable to 'express:debug'. This will provide detailed debugging information for your Express application.