Which of the following databases is a NoSQL database?
- MySQL
- SQLite
- MongoDB
- PostgreSQL
MongoDB is a NoSQL database, known for its flexibility in handling unstructured or semi-structured data. It uses a document-oriented data model, making it a popular choice for applications that require dynamic, schema-less data storage. MySQL, SQLite, and PostgreSQL are all SQL databases, which follow a structured, table-based data model.
Which of the following database operations is atomic, consistent, isolated, and durable (ACID)?
- INSERT
- SELECT
- DELETE
- UPDATE
The "INSERT" operation in a database is often ACID compliant. It ensures that data is inserted as a complete unit (atomic), maintains consistency, isolation from other transactions, and durability. Other operations may or may not meet all these ACID properties depending on the database system and transaction configuration.
Overusing mocks and stubs can lead to tests that are ______ and do not adequately represent the system's behavior.
- Fragile
- Robust
- Isolated
- Comprehensive
Overusing mocks and stubs in testing can make tests fragile. A fragile test is one that breaks easily when the internal implementation of the system changes, and it may not adequately represent the system's actual behavior because it's too tightly coupled to the implementation details.
In the fs module, how can you create a new file?
- createFile
- newFile
- writeFile
- makeFile
In the fs module, you can create a new file using the writeFile method. This method takes the file path and the data to be written to the file as parameters. If the file does not exist, it will be created; if it exists, its contents will be replaced.
How can you integrate ESLint with a continuous integration (CI) service to ensure code quality?
- Run ESLint manually before each commit
- Add an ESLint script in package.json and run it in CI pipelines
- Create a separate ESLint CI service
- ESLint doesn't integrate with CI services
Integrating ESLint with CI services involves adding an ESLint script in package.json and running it in CI pipelines. This ensures that code quality checks are automated during the CI/CD process. The other options do not describe a recommended way to integrate ESLint with CI.
How can multiple asynchronous operations be performed concurrently using Promise.all?
- Promise.all([promise1, promise2, promise3])
- Promise.race([promise1, promise2, promise3])
- Promise.parallel([promise1, promise2, promise3])
- Promise.concurrent([promise1, promise2, promise3])
In JavaScript, to perform multiple asynchronous operations concurrently, you can use Promise.all. It takes an array of promises as an argument, and it resolves when all promises in the array have resolved. Options B, C, and D are not valid methods for concurrent execution using Promises.
What is the primary purpose of using lifecycle hooks in npm scripts?
- To execute custom actions at specific points in the package's lifecycle
- To automatically update the package's dependencies
- To configure package metadata
- To define package scripts
Lifecycle hooks in npm scripts allow you to execute custom actions at specific points in the package's lifecycle, such as before or after installation, publication, or uninstallation. They are used for tasks like setting up environment variables, compiling code, or cleaning up resources.
What is the significance of the next function in error-handling middleware in Express?
- It sends a response to the client
- It terminates the application
- It passes control to the next middleware
- It logs the error
In Express.js, the next function, when called within an error-handling middleware, passes control to the next middleware in the chain. This is essential for the error-handling flow, as it allows you to continue processing additional error-handling middleware or routes. It does not send a response to the client or terminate the application, but it facilitates the flow of handling errors.
In what scenarios would using spies be preferable over mocks and stubs?
- When you need to assert on method invocations
- When you need to control the return value of a function
- When you want to isolate the code under test
- When you want to use real implementations
Using spies is preferable over mocks and stubs when you need to assert on method invocations, as spies can record and report on method calls without altering the original method behavior. Mocks and stubs are more focused on controlling method behavior. Options 2, 3, and 4 are not typical scenarios for using spies.
In a sharded database architecture, how can query performance be optimized to minimize cross-shard queries?
- By using a well-defined shard key that distributes data evenly, routing queries to specific shards based on the shard key, avoiding unbounded queries that touch all shards, and using secondary indexes efficiently.
- Cross-shard queries are inevitable and cannot be minimized in a sharded database architecture.
- Query performance in sharded databases cannot be optimized.
- By disabling sharding for specific collections to prevent cross-shard queries.
In a sharded database, optimizing query performance involves selecting an appropriate shard key, routing queries effectively, and avoiding operations that require querying all shards, thus reducing the impact of cross-shard queries.
How can mismanagement of dependencies and devDependencies impact the deployment of a Node.js application?
- It has no impact on deployment
- It may lead to security vulnerabilities
- It speeds up deployment
- It reduces application size
Mismanagement of dependencies and devDependencies can significantly impact deployment by potentially introducing security vulnerabilities. When dependencies are not properly managed, outdated or insecure packages may be included in the application, posing security risks.
In CRUD operations, which HTTP status code is suitable for a successful Create operation in RESTful APIs?
- 200 OK
- 201 Created
- 204 No Content
- 202 Accepted
In RESTful APIs, the HTTP status code "201 Created" is suitable for a successful Create operation. It indicates that the request has been fulfilled, and a new resource has been created as a result of it. Other status codes like "200 OK" and "204 No Content" are often used for different purposes.