What does the process object in Node.js primarily provide information about?

  • Operating system processes
  • Web browser processes
  • File I/O processes
  • Database processes
The process object in Node.js primarily provides information about operating system processes. It allows you to interact with and control the Node.js process, such as accessing command line arguments, environment variables, and exiting the process. It is not related to web browser, file I/O, or database processes.

When designing systems with Non-Blocking I/O, careful consideration must be given to avoid ________, where multiple asynchronous operations are competing for resources.

  • Callback Hell
  • Deadlock
  • Blocking I/O
  • Synchronous Execution
When designing systems with Non-Blocking I/O, careful consideration must be given to avoid "Callback Hell," also known as "Callback Pyramid" or "Callback Spaghetti." This occurs when multiple asynchronous operations are nested deeply, making code difficult to read and maintain.

How can you implement template inheritance in Pug?

  • extend layout.pug
  • include layout.pug
  • inherit layout.pug
  • template layout.pug
In Pug, template inheritance is implemented using the extend keyword followed by the name of the layout file. This allows child templates to inherit the structure and content of the specified layout file. The other options (include, inherit, and template) are not used for template inheritance in Pug.

How can you optimize the performance of a SQL query that reads a large amount of data?

  • Use indexes on columns frequently queried.
  • Avoid joins and subqueries.
  • Increase the page size of the database.
  • Fetch all data at once to minimize network latency.
To optimize the performance of a SQL query reading large data, you should use indexes on columns frequently queried. Indexes improve data retrieval speed. The other options may not necessarily lead to performance improvements and can even degrade performance.

You are developing a Node.js application that should gracefully shut down when it receives a termination signal. How would you accomplish this using the process object?

  • process.on('terminate', () => { /* Graceful shutdown code */ });
  • process.kill('SIGTERM', process.pid);
  • process.exit(0);
  • process.handleTermination(() => { /* Graceful shutdown code */ });
To gracefully shut down a Node.js application upon receiving a termination signal, you should use process.on('terminate', () => { /* Graceful shutdown code */ });. This registers an event handler for the 'terminate' event. The other options either do not handle termination signals gracefully or are incorrect syntax.

You are tasked with implementing a secure authentication system for a web application. What considerations should you make to ensure the security of user credentials and session information?

  • Store passwords in plain text
  • Use a secure hashing algorithm for password storage
  • Use HTTP for transmitting sensitive data
  • Keep session tokens in local storage
To ensure the security of user credentials and session information, you should use a secure hashing algorithm (like bcrypt) to store passwords, not store them in plain text. Additionally, sensitive data should not be transmitted over HTTP, and session tokens should be stored securely (not in local storage, which is vulnerable to cross-site scripting attacks).

What considerations should be made when deciding between using a mock and a stub in a test case?

  • The complexity of the test scenario
  • The need for recording method calls
  • The desire to control method behavior
  • The size of the test data
When deciding between using a mock and a stub in a test case, considerations should include the complexity of the test scenario, as mocks are generally more complex than stubs. Recording method calls is a characteristic of mocks, and controlling method behavior is a characteristic of stubs. The size of the test data is typically not directly related to choosing between mocks and stubs.

What is the first line of defense against injection attacks in web applications?

  • Using a web application firewall (WAF).
  • Escaping user input before displaying it.
  • Using strong authentication mechanisms.
  • Regularly updating server software.
The first line of defense against injection attacks in web applications is to escape or sanitize user input before displaying it on web pages. This prevents malicious code from being executed, protecting against common injection attacks like SQL injection and cross-site scripting (XSS).

When securing a web application using JWT, implementing ________ helps in mitigating the risk of token interception.

  • Token expiration
  • Strong encryption
  • Public key authentication
  • Rate limiting
When securing a web application with JWT (JSON Web Tokens), implementing strong encryption is crucial to mitigate the risk of token interception. Encryption ensures that the token's content remains confidential even if intercepted. Token expiration (Option 1) deals with token validity periods, while public key authentication (Option 3) is related to how JWT signatures are verified. Rate limiting (Option 4) is a measure to control access but doesn't directly address token interception.

You are tasked with evolving the schema of a critical, high-traffic database while minimizing downtime and data inconsistency. What strategies would you employ to safely apply schema migrations?

  • Use database migration tools with rollback support.
  • Apply schema changes during off-peak hours.
  • Utilize database versioning and backward-compatible changes.
  • Pause the database for maintenance during schema updates.
Option (1) is a common approach as it allows you to apply changes with rollback capabilities. Option (2) is valid to minimize the impact on users. Option (3) is also important, using versioning and backward-compatible changes ensures a smoother transition. Option (4) is typically not recommended, as it causes downtime.