In Jest, to isolate a module from its dependencies for more focused unit testing, you would use ______.

  • mock
  • stub
  • spy
  • inject
In Jest, you can use the mock function to isolate a module from its dependencies. This allows you to replace the real dependencies with mock implementations for focused unit testing.

In ESLint, the ______ property in the configuration file can be used to define global variables.

  • Globals
  • Environment
  • Globals
  • Rules
In ESLint, the globals property in the configuration file is used to define global variables that are accessible throughout your code without triggering linting errors. This allows you to specify variables that are declared externally or provided by the environment. The environment option is used to specify which environments your code runs in, but it's not used to define individual global variables. The rules property is used for configuring ESLint rules.

You are designing a logging system in Node.js where multiple loggers are listening to logging events. How would you manage and optimize the event listeners to avoid potential memory leaks?

  • event.setMaxListeners(1)
  • event.on('log', loggerCallback)
  • event.prependListener('log', loggerCallback)
  • event.removeListener('log', loggerCallback)
To avoid memory leaks when multiple loggers are listening to logging events, it's crucial to remove listeners when they are no longer needed. The event.removeListener() method should be used to remove specific listeners, ensuring that you free up memory and resources when loggers are no longer required. The other options are related to listener management but do not directly address memory leaks.

If a package is required for running the tests, it should ideally be listed under ________.

  • devDependencies
  • dependencies
  • peerDependencies
  • optionalDependencies
If a package is required for running the tests, it should ideally be listed under devDependencies. This ensures that the testing dependencies are only installed during development and testing phases, keeping the production environment clean from unnecessary packages.

Which of the following is a common technique used for optimizing database queries?

  • Query caching
  • Adding more indexes
  • Increasing database complexity
  • Ignoring query performance
One common technique used for optimizing database queries is query caching. It involves storing frequently used query results in memory, reducing the need to re-execute the same query, and improving response times.

In which format is image data usually sent to the server when uploading files in a web application?

  • JSON
  • XML
  • Base64
  • CSV
Image data is usually sent to the server in Base64 format when uploading files in a web application. This format allows binary data (like images) to be represented as a string, making it easier to transmit as part of an HTTP request. The other options (JSON, XML, and CSV) are not typically used for sending binary data like images.

How can you compare two buffers in Node.js to check if they are equal?

  • Using the == operator
  • Using the compare() method
  • By converting them to strings and using ===
  • Using the isEqual() function
To compare two buffers in Node.js, you should use the compare() method. The == operator and === with string conversion won't provide accurate results, and there's no isEqual() function for buffers in Node.js.

Which of the following can be considered as a performance bottleneck in a web application?

  • High network latency
  • Code comments
  • Proper error handling
  • Modular code structure
High network latency can be considered a performance bottleneck in a web application. Slow data transfer between the client and server due to network latency can significantly impact the application's performance. Code comments, proper error handling, and modular code structure, while important for code quality, are not typically performance bottlenecks.

Using the BigInt data type, you can represent integers larger than ______.

  • 2^31 - 1
  • 2^53 - 1
  • 2^63 - 1
  • 2^128 - 1
Using the BigInt data type in JavaScript, you can represent integers larger than 2^128 - 1. BigInts are not restricted by the usual 53-bit limit of regular JavaScript numbers (doubles), allowing you to work with much larger integers.

You are developing an Express.js application and you realize that some of the errors are not being caught by your error-handling middleware. What should you consider while debugging this issue?

  • Check the order of middleware execution
  • Increase the stack size of the Node.js process
  • Disable error handling for those specific routes
  • Increase the timeout for asynchronous operations
In Express.js, middleware functions are executed in the order they are defined. If some errors are not being caught by your error-handling middleware, it's crucial to check the order of middleware execution. Errors should be handled after they are thrown, so make sure your error-handling middleware comes after the routes that might throw errors.

Which object is primarily used to emit events in Node.js?

  • Emitter
  • EventEmitter
  • EventObject
  • EventHandler
In Node.js, the primary object used to emit events is EventEmitter. It's a built-in module that provides the core functionality for event-driven programming. Options A, C, and D are not the standard objects for emitting events in Node.js.

When using the fs module to write data to a file, what considerations must be taken into account regarding concurrency?

  • Node.js automatically handles concurrency
  • Concurrency is not a concern when using fs
  • Ensure proper locking mechanisms for concurrent writes
  • Concurrency is only an issue with network operations
When working with the fs module, you must consider concurrency, especially when multiple processes or threads are writing to the same file simultaneously. It's important to implement proper locking mechanisms, such as file locking, to prevent data corruption. Node.js does not handle concurrency automatically.