In a token-based authentication system, using a ______ approach helps in reducing the risk of token interception and replay attacks.
- Stateless
- Stateful
- Hybrid
- Cookie-based
In a token-based authentication system, a "stateless" approach is used to reduce the risk of token interception and replay attacks. Stateful approaches require server-side storage, while stateless approaches are based on self-contained tokens, which do not rely on server-side storage, making them more secure.
When a JavaScript function is executed, a new execution context is created, and a special object called ________ is created.
- "this"
- "global"
- "function"
- "execution"
When a JavaScript function is executed, a new execution context is created, and a special object called the "execution context" is created. This execution context contains information about the function's variables and scope.
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.
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.
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.
When designing schemas for large-scale systems, the principle of ________ involves dividing the dataset into smaller, more manageable parts.
- Sharding
- Normalization
- Aggregation
- Indexing
The principle of "sharding" involves dividing the dataset into smaller, more manageable parts, typically based on a certain criteria like range or hash, to distribute data across multiple servers or nodes in a distributed system. Sharding is a crucial concept in achieving horizontal scalability in databases.
When configuring the static files directory in Express.js, the path specified is relative to the ______ directory.
- current
- project
- root
- parent
When configuring the static files directory in Express.js, the path specified is relative to the root directory of your project. This means that you specify the path from the root of your project's directory structure.
For optimal performance when querying a large dataset in a NoSQL database, it is crucial to have proper ______ in place.
- Indexing
- Sharding
- Versioning
- Compression
For optimal performance when querying a large dataset in a NoSQL database, it is crucial to have proper indexing in place. Indexes help the database quickly locate and retrieve the data, reducing query response times.
You are developing a web application that needs to make API requests to a server on a different domain. How would you handle CORS to ensure that your web application can interact with the server without any issues?
- Set up a server-side proxy to forward requests to the other domain.
- Enable CORS on the server by adding appropriate headers to allow cross-origin requests.
- Use JSONP for making cross-domain requests.
- Disable CORS restrictions in the browser settings.
The correct approach is to enable CORS on the server by adding the appropriate headers that allow cross-origin requests. Option A can be a workaround, but it's not the best practice. Option C is an outdated method, and option D is not a recommended security practice.
How can prototype pollution vulnerabilities be mitigated in JavaScript applications?
- Avoid using third-party libraries
- Use strong typing for all variables
- Validate and sanitize user input
- Disable JavaScript prototypes
To mitigate prototype pollution vulnerabilities in JavaScript applications, it's crucial to validate and sanitize user input. This prevents malicious input from corrupting object prototypes. Avoiding third-party libraries and using strong typing are good practices but do not directly address prototype pollution. Disabling prototypes would break core JavaScript functionality.