What is the main purpose of the global object in Node.js?

  • To manage global variables
  • To handle exceptions globally
  • To control the execution flow of the program
  • To define local variables
The main purpose of the global object in Node.js is to manage global variables and provide a context for globally accessible methods and properties. It is not primarily responsible for handling exceptions, controlling execution flow, or defining local variables.

In Express.js, how does the order in which routes are defined affect the routing mechanism?

  • Routes are matched in a random order
  • Routes are matched in the order they are defined
  • Routes are matched in reverse order
  • Routes are matched based on alphabetical order
In Express.js, the order in which routes are defined affects the routing mechanism. Routes are matched in the order they are defined, and the first matching route is executed. This means that the order of route definitions is crucial as it determines which route will handle a request.

You are developing an NPM package and are about to publish a version with experimental features. What is the semantic versioning compliant way to version this release?

  • 0.0.1
  • 0.1.0
  • 1.0.0
  • 2.0.0
According to SemVer, when you have experimental or initial releases that may have breaking changes, you should start with version 0.0.1. This signifies that the package is in the early development stage.

How does parameterized query help in preventing SQL Injection attacks?

  • It escapes special characters in user input
  • It encrypts SQL queries before execution
  • It restricts SQL queries to a predefined set
  • It validates SQL queries against a whitelist
A parameterized query helps prevent SQL Injection attacks by escaping special characters in user input. This ensures that user input is treated as data and not executable code. The other options do not accurately describe how parameterized queries work against SQL Injection.

In a test for a method that processes data retrieved from a database, how would you use stubbing to simulate different scenarios and edge cases related to data retrieval?

  • Stub the entire database to return predefined data
  • Stub only the network communication with the database
  • Stub the method that retrieves data, returning different values
  • Avoid stubbing and use the real database
When testing a method that processes data from a database, you should use stubbing to simulate different scenarios and edge cases related to data retrieval. This can be achieved by stubbing the method that retrieves data and having it return different values for each test scenario. Stubbing the entire database may lead to over-complicated tests, and avoiding stubbing by using the real database can result in unreliable and slow tests. Stubbing only network communication is not sufficient for simulating different scenarios related to data retrieval.

In Express, which method is used to start a server listening for connections?

  • app.listen()
  • server.start()
  • express.startServer()
  • node.start()
In Express, you use the app.listen() method to start a server that listens for incoming connections. This method binds the server to a specified port and hostname, allowing it to handle HTTP requests. The other options are not valid methods for starting an Express server.

In Express.js, what does the next() function do in middleware?

  • Ends the request-response cycle
  • Sends an HTTP response
  • Passes control to the next middleware function
  • Logs a message to the console
In Express.js, the next() function is used in middleware to pass control to the next middleware function in the stack. It allows the request to continue processing through subsequent middleware functions. If you don't call next(), the request-response cycle may be terminated, and subsequent middleware or route handlers won't be executed.

Which of the following is a common technique used for implementing full-text search in databases?

  • Regular Expressions
  • Binary Search
  • Inverted Index
  • Depth-First Search
A common technique for implementing full-text search in databases is the use of an inverted index. This index stores a list of words or terms along with the locations where they appear in the documents, making it efficient for searching large volumes of text. Regular expressions, binary search, and depth-first search are not typically used for full-text search in databases.

How does the use of subqueries impact the performance of SQL queries, and how can it be optimized?

  • Subqueries can slow down SQL queries significantly. They execute for each row in the outer query result and may lead to performance bottlenecks. Optimization techniques include using JOINs, EXISTS, or rewriting queries as JOINs, ensuring indexes on relevant columns, and limiting the result set size.
  • Subqueries have no impact on SQL query performance.
  • Subqueries always improve SQL query performance.
  • Subqueries should be avoided, but if used, no optimization is possible.
Subqueries can impact SQL query performance negatively if not used carefully. They can lead to increased query execution times, and optimizing them involves using appropriate techniques to minimize their impact.

You have been assigned to optimize the CRUD operations of a microservices-based application where each microservice handles its own database. How would you ensure the consistency and integrity of data across different microservices while performing Create and Update operations?

  • Implement a distributed transaction coordinator
  • Use REST APIs for communication
  • Share a centralized database
  • Implement message queues
To ensure the consistency and integrity of data across different microservices in a microservices-based application, implementing a distributed transaction coordinator (Option 1) is a suitable approach. This coordinator can manage transactions across multiple microservices, ensuring that Create and Update operations either succeed or fail together, preserving data integrity. Using REST APIs (Option 2) for communication is a common practice but doesn't guarantee transactional consistency. Sharing a centralized database (Option 3) can create tight coupling and hinder the benefits of microservices. Implementing message queues (Option 4) helps with asynchronous communication but doesn't inherently guarantee data consistency across microservices.