You are tasked with developing a file upload module in Node.js. The files uploaded by users are binary data. How would you handle the incoming binary data to ensure data integrity and optimal resource utilization?

  • Use streams to handle and process binary data in chunks
  • Read the entire binary data into memory before processing
  • Convert binary data to hexadecimal for storage
  • Store binary data in a JSON format
To ensure data integrity and optimal resource utilization when handling binary data in a file upload module, it's best to use streams to handle and process binary data in chunks. This approach minimizes memory usage and ensures data integrity. Reading the entire binary data into memory is not efficient, and the other options are not suitable for storing binary data.

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.

Can you modify the package.json file after it has been created by the npm init command?

  • Yes, but only with admin privileges
  • No, it's read-only
  • Yes, it can be edited anytime
  • Yes, but only during project initialization
Yes, you can modify the package.json file after it has been created by the npm init command. It's a JSON configuration file that stores information about your project, and you can update it to add dependencies, scripts, and other project-related settings. It's a fundamental part of managing Node.js projects.

You are building a real-time data processing system where tasks are dependent on the completion of previous tasks. How would you structure your Promises/async functions to ensure the sequence is maintained?

  • Using async/await
  • Using Promise.then()
  • Using Promise.race()
  • Using setTimeout()
To ensure the sequence of tasks is maintained in a real-time data processing system, you should structure your code using async/await. This allows you to write asynchronous code in a more synchronous style, ensuring that each task awaits the completion of the previous one. The other options are not typically used for sequential task execution.

What is the output of the following code snippet: console.log(1 == '1')?

  • TRUE
  • FALSE
  • undefined
The output of the code snippet is true. In JavaScript, the == operator performs type coercion, so it converts the string '1' to a number before comparing, and 1 is equal to 1.

What is the primary use of Streams in Node.js?

  • Managing database connections
  • Handling HTTP requests and responses
  • Storing configuration data
  • Sorting arrays
The primary use of Streams in Node.js is for handling data in a streaming fashion, especially for reading and writing data efficiently. They are commonly used for handling HTTP requests and responses, file I/O, and more, where data can be processed in smaller chunks without loading the entire dataset into memory.

How does normalizing database tables impact the Read and Update operations in CRUD?

  • Improves Read performance, may complicate Updates
  • Improves Update performance, may slow down Reads
  • Has no impact on either Read or Update operations
  • Improves both Read and Update operations
Normalizing database tables often improves Read performance by reducing data redundancy. However, it may complicate Update operations since data may be spread across multiple tables, requiring joins. Option 2 is not generally true as normalization tends to have a positive impact on Update operations. Option 4 is an oversimplification.

What does the resolve function do in a JavaScript Promise?

  • It is called when an error occurs.
  • It is called when the Promise is rejected.
  • It is called when the Promise is fulfilled with a value.
  • It is called to cancel the Promise.
The resolve function in a JavaScript Promise is called when the Promise is fulfilled successfully with a value. It signifies that the asynchronous operation inside the Promise has completed successfully, and the value provided in the resolve function is the result.

In what scenario would a package be listed in both dependencies and devDependencies?

  • When the package is a development tool
  • When it's a runtime dependency
  • When it's a peer dependency
  • When it's a transitive dependency
A package can be listed in both dependencies and devDependencies when it's a development tool that is needed during both development and runtime. An example might be a testing library or build tool.

In Express.js, how can you handle errors occurring in asynchronous code within a route handler?

  • try-catch
  • next(error)
  • return error;
  • res.error(error)
In Express.js, you can handle errors occurring in asynchronous code within a route handler by calling next(error). This passes the error to the error-handling middleware or the default error handler, allowing you to centralize error handling. Using a try-catch block won't catch asynchronous errors, and the other options are not standard practices for error handling in Express.js.