Cache ______ is a situation where multiple requests are made to a resource that is expensive to produce, causing a surge in load.
- Throttling
- Bursting
- Collapsing
- Overloading
Cache bursting is a situation where multiple requests are made to a resource that is expensive to produce, causing a surge in load. It typically occurs when cached data expires or when the cache is invalidated.
How can you create a custom lifecycle event that runs a series of npm scripts in a specified order?
- Use the pre and post prefixes with custom script names
- Use a third-party package like "npm-run-all"
- It's not possible to create custom lifecycle events
- Use JavaScript code within package.json
You can create a custom lifecycle event that runs a series of npm scripts in a specified order by using a third-party package like "npm-run-all." This package allows you to define complex run scripts in a convenient way, specifying the order of execution and handling dependencies between scripts.
How can you simulate user actions like clicks or keyboard inputs in Jest?
- jest.spyOn()
- jest.mock()
- jest.fn()
- jest.simulate()
In Jest, you can simulate user actions like clicks or keyboard inputs using jest.fn(). This allows you to create mock functions that can simulate user interactions and track their calls. The other options have different purposes; jest.spyOn() is used to spy on method calls, jest.mock() is used to mock modules, and jest.simulate() is not a valid Jest method for simulating user actions.
In which scenario would denormalization be considered a suitable option for query optimization?
- When you want to minimize data redundancy and improve data integrity.
- When you want to improve query performance, even at the cost of some data redundancy and update anomalies.
- Denormalization is never considered a suitable option for query optimization.
- When you want to reduce the size of the database.
Denormalization is considered when you want to optimize read-heavy queries and reduce the number of JOIN operations. It involves introducing redundancy to improve query performance, but it can lead to data anomalies.
In JavaScript, a variable declared without the var, let, or const keyword inside a function becomes a property of the ________ object.
- "window"
- "global"
- "local"
- "this"
In JavaScript, a variable declared without the var, let, or const keyword inside a function becomes a property of the "global" object. This can lead to unexpected behavior, so it's important to declare variables properly.
What strategies can be employed to optimize aggregation queries in NoSQL databases like MongoDB?
- Aggregation queries in NoSQL databases like MongoDB can be optimized by using the aggregation framework provided by MongoDB, creating proper indexes on fields used in aggregation stages, leveraging server resources efficiently, and using projection to limit the output data size.
- Aggregation queries in NoSQL databases cannot be optimized.
- Aggregation queries in NoSQL databases can only be optimized by using raw database queries with no additional strategies.
- Aggregation queries in NoSQL databases should be avoided altogether.
Aggregation queries in NoSQL databases can be resource-intensive, but they can be optimized using MongoDB's aggregation framework and other techniques to improve query performance.
How can you handle CORS to allow cookies to be included in requests?
- Access-Control-Allow-Origin: *
- Access-Control-Allow-Credentials: true
- Access-Control-Allow-Headers: *
- Access-Control-Allow-Methods: GET, POST
To allow cookies to be included in CORS requests, you should set the Access-Control-Allow-Credentials header to true. The other options are related to different aspects of CORS, but they don't specifically enable cookie handling.
In the context of testing, what is the main difference between a mock and a stub?
- Stubs are used for functions, while mocks are used for objects
- Mocks record and verify interactions, while stubs only simulate behavior
- Stubs are only used in integration tests, while mocks are used in unit tests
- Mocks are less flexible than stubs
The primary difference between a mock and a stub is that mocks record and verify interactions between the code under test and the dependencies, whereas stubs only simulate the behavior of dependencies. Mocks are used to ensure that specific interactions occur as expected, while stubs focus on controlling the response of functions or methods.
In Express.js, how can middleware be utilized to implement authorization checks for different routes?
- Middleware can't be used for authorization checks in Express.js.
- Middleware functions can be added to route definitions to execute specific authorization logic before handling a request.
- Middleware can only be used for logging purposes in Express.js.
- Authorization checks can only be done in the route handler functions.
Middleware in Express.js is versatile and can be used for various purposes, including implementing authorization checks. By adding middleware functions to specific route definitions, you can ensure that certain authorization logic is executed before the route handler processes the request.
How can the 'done' callback be used in asynchronous testing with Mocha?
- done is used to terminate the Mocha test suite prematurely.
- done is used to indicate that the test is asynchronous and should wait for it to complete.
- done is used to skip a test case in Mocha.
- done is not used in Mocha for asynchronous testing.
In Mocha, the done callback is used to indicate that a test is asynchronous and should wait for it to complete before considering the test case finished. It prevents the test case from finishing prematurely. The other options provide incorrect information about the use of done.