What happens when an error is thrown inside an async function and it is not caught within the function?

  • The error will be caught by the global error handler and potentially crash the application.
  • The error is automatically logged to the console, but the function continues executing.
  • The error is ignored, and the function continues executing.
  • The error is caught by the JavaScript runtime and handled silently.
If an error is thrown inside an async function and is not caught within the function, it will propagate to the global error handler, which can potentially crash the application. Proper error handling is crucial in async code.

How can you define optional route parameters in Express.js?

  • Enclose parameters in square brackets [param]
  • Use the optional keyword before the parameter
  • Use the ? symbol after the parameter
  • Wrap parameters in parentheses (param)
In Express.js, you can define optional route parameters by using the ? symbol after the parameter name, like /route/:param?. This makes the parameter optional, allowing it to match both routes with and without that parameter. The other options do not represent the correct way to define optional route parameters in Express.js.

In a system following eventual consistency, what implications does it have on Read operations after a Write operation?

  • Strong consistency
  • Read operations may return stale data
  • Write operations are blocked until consistency is achieved
  • Write operations are delayed
In a system with eventual consistency, Read operations may return stale or outdated data for a period of time after a Write operation. This is because eventual consistency prioritizes availability and performance over strict consistency. Strong consistency (Option 1) ensures that all reads return the most recent write but may lead to higher latency. Options 3 and 4 are not characteristic of eventual consistency.

________ is a security practice that involves encoding information so that only authorized parties can access it.

  • Encryption
  • Hashing
  • Salting
  • Obfuscation
Encryption is a security practice that involves encoding information in a way that only authorized parties with the decryption key can access it. This is commonly used to protect sensitive data during transmission and storage.

In a complex CORS scenario, how can you selectively allow certain types of requests while denying others?

  • Create custom middleware
  • Set Access-Control-Allow-Origin to *
  • Use the OPTIONS method
  • Configure server-side routing
In complex CORS scenarios, you can selectively allow or deny requests by creating custom middleware on your server. This middleware can inspect the request headers, methods, or other criteria to determine whether to allow or deny a request. The other options are components of CORS but do not provide fine-grained control over request types.

The fs.watch method is used to watch for changes in a file or a directory but may not be consistent across platforms due to its reliance on ______.

  • inotify
  • polling
  • event-driven
  • file system events
The fs.watch method relies on polling on some platforms to detect file and directory changes. This polling approach may not be consistent across platforms and can have performance implications.

In Express.js, the ______ method is commonly used to protect routes and ensure that only authenticated users can access them.

  • authenticate
  • secure
  • authorize
  • validate
In Express.js, the authorize method is commonly used to protect routes and ensure that only authenticated users can access them. This is often achieved through middleware functions that check for authentication and authorization before allowing access. The other options may not be standard methods for this purpose in Express.js.

Which method in Express.js is used to serve static files?

  • app.static()
  • app.useStatic()
  • app.serveStatic()
  • app.use()
In Express.js, the app.use(express.static()) method is used to serve static files. This method allows you to specify a directory from which Express should serve static assets like images, CSS, and JavaScript. The other options are not valid methods for serving static files in Express.

You are tasked with improving the performance of a database that experiences heavy read and write operations. How would you balance the use of indexing to improve read performance while minimizing the impact on write performance?

  • Add Indexes to All Columns for Faster Reads
  • Use Covering Indexes for Frequently Queried Columns
  • Implement Partitioned Tables to Isolate Write-Intensive Data
  • Regularly Rebuild All Indexes for Maximum Performance
To balance the use of indexing in a database with heavy read and write operations, it's crucial to use Covering Indexes for frequently queried columns. These indexes include all the necessary data for the query, reducing the need to access the main table. Implementing Partitioned Tables can isolate write-intensive data from read-intensive data, improving write performance. Adding indexes to all columns and regularly rebuilding all indexes can lead to unnecessary overhead and hinder write performance.

Which method should be used to handle the rejection of a Promise?

  • reject()
  • catch()
  • error()
  • failure()
To handle the rejection of a Promise, you should use the catch() method. It allows you to specify what to do when the Promise is rejected with an error. The other options are not standard methods for handling Promise rejection in JavaScript.

Connection to a NoSQL database like MongoDB in Node.js usually returns a ______ object.

  • MongoClient
  • Promise
  • HttpServer
  • Buffer
When connecting to a NoSQL database like MongoDB in Node.js, you typically get a MongoClient object. This object represents the database connection and allows you to perform various database operations. The other options are not related to MongoDB connections.

What is the significance of the HTTP status code in the response of an Express API, and how does it affect client-server interaction?

  • HTTP status codes are optional and don't impact client-server interaction
  • HTTP status codes indicate the type of response and guide client behavior
  • HTTP status codes are primarily for server documentation
  • HTTP status codes are used to encrypt the API response
HTTP status codes are essential in the response of an Express API. They indicate the type of response and guide client behavior. For example, a 200 OK status indicates success, while a 404 Not Found status indicates a resource was not found. Proper status codes enhance communication and handling between the client and server.