Which of the following is the primary role of middleware in Express.js?

  • Handling client-side routing
  • Handling server-side routing
  • Managing HTTP requests and responses
  • Creating database schemas
The primary role of middleware in Express.js is to manage HTTP requests and responses. Middleware functions are executed in the order they are defined in the Express application and can perform various tasks such as authentication, logging, and modifying request/response objects. They play a crucial role in the request/response cycle.

Which keyword is used to export multiple things from a module in JavaScript?

  • import
  • export
  • require
  • module
In JavaScript, the export keyword is used to export multiple things from a module. It allows you to specify which functions, objects, or variables should be accessible from outside the module. The import keyword is used for importing from modules, not exporting. The require and module keywords are used in CommonJS, a different module system.

How does JavaScript handle circular dependencies between modules?

  • JavaScript throws an error and does not allow circular dependencies.
  • JavaScript allows circular dependencies, and they are resolved at runtime.
  • JavaScript handles circular dependencies by allowing them but ensuring that each module loads only once.
  • Circular dependencies are not supported in JavaScript.
JavaScript allows circular dependencies, but it ensures that each module is only executed once. This is achieved through a mechanism called "module caching."

When handling errors in an async function, if an error is not caught within the function, it will cause the returned Promise to be in a ________ state.

  • Pending
  • Fulfilled
  • Rejected
  • Completed
When an uncaught error occurs in an async function, the returned Promise will be in a "Rejected" state. In the Promise lifecycle, it can start as "Pending," move to "Fulfilled" upon success, or "Rejected" upon an error.

Why would you use the global object to store data in a Node.js application?

  • To share data between different Node.js modules.
  • To encapsulate data and prevent it from being accessed globally.
  • To improve application performance by reducing memory usage.
  • To ensure data persistence across application runs.
The global object in Node.js can be used to store data that needs to be shared between different Node.js modules. It acts as a global namespace for variables and allows you to share data across different parts of your application. The other options do not accurately describe the common use case for the global object.

How does semantic versioning handle pre-release versions and build metadata?

  • Pre-release versions are denoted with a hyphen and can include additional labels and numbers. Build metadata is indicated with a plus sign.
  • Pre-release versions use square brackets to specify additional labels, and build metadata uses parentheses.
  • Pre-release versions are marked with a plus sign, and build metadata is indicated with a hyphen.
  • Pre-release versions are not supported in semantic versioning.
Semantic versioning allows pre-release versions to be denoted with a hyphen, followed by additional labels and numbers, and build metadata is indicated with a plus sign. This is essential for managing versions during development and testing phases.

Which data type in JavaScript can be used to store a sequence of characters?

  • char
  • sequence
  • string
  • text
In JavaScript, the string data type is used to store a sequence of characters. The char data type doesn't exist in JavaScript, and neither sequence nor text are valid data types for this purpose.

When an error occurs in Node.js, the error object is typically an instance of __________.

  • Error
  • Exception
  • ErrorObject
  • Err
In Node.js, when an error occurs, the error object is typically an instance of the built-in Error object. This object contains valuable information about the error, such as a message and a stack trace.

When are CORS preflight requests sent by the browser?

  • Before making certain types of requests
  • After a successful request
  • Randomly to check server compatibility
  • Only when cookies are involved
CORS preflight requests are sent by the browser before making certain types of requests, specifically those that could have an impact on server security or state. These preflight requests are used to check with the server if the actual request (e.g., a cross-origin POST request with custom headers) is allowed, ensuring server compatibility and security.

You are working on a Node.js project with a team, and you notice that the package-lock.json file is frequently causing merge conflicts. How would you resolve or minimize such conflicts while ensuring consistent dependency resolution?

  • Remove the package-lock.json file entirely
  • Use Yarn instead of npm
  • Use a tool like npm ci and enforce it in your team's workflow
  • Manually edit the package-lock.json file in case of conflicts
To minimize package-lock.json merge conflicts, you should use a tool like npm ci in your team's workflow. npm ci installs dependencies based on the package-lock.json and ensures consistent dependency resolution. Options 1 and 2 are not recommended, and option 4 is not a practical solution.